Why would you even expose yourself to these risks? why not just use 'nix commands properly instead of trying to do things in an overly complicated, unsafe way?
Everyone should completely disregard all advice in this article. Use `find` and globbing instead to do your mass-deleting.
Ah, that worked thanks for teaching me, this is great, I've updated and given you credit. I think substack might be eating the double space as there is only one space after the slash above.
You really misunderstand the -I parameter. In your example of "echo seq 10 | xargs -IX X", the second X has to be a proper command and it is not substituted (i.e. you don't get 'seq 10' there). So you are trying to start the X window manager, which obviously doesn't work.
Perhaps re-reading the documentation of xargs might be in order. Perhaps don't fulminate against tools you don't understand.
$ touch '--no-preserve-root / foo' 'foo'
$ rm $(ls | grep foo)
I've literally never found this in a real life file system, why should I worry about it?
I've never used xargs. And I usually need to put it in a list that I'll read several times, like:
```
list=$(whatever) && fuser $list || rm -- $list
```
or
```
for i in $(whatever) ; do fuser "$i" || rm -- "$i" ; done
```
for example to be sure that there's no open files there (I work with databases)
$ echo "bad bash" > secret.txt
$ echo "" > "-f foo && cat secret.txt"
$ ls | grep foo | sed 's/.*/rm &/' | bash
bad bash
$ echo "" > "-f foo && rm -rf ~/"
$ ls | grep foo | sed 's/.*/rm &/' | bash
Why would you even expose yourself to these risks? why not just use 'nix commands properly instead of trying to do things in an overly complicated, unsafe way?
Everyone should completely disregard all advice in this article. Use `find` and globbing instead to do your mass-deleting.
None of this is good advice. You should use the find command.
Please elaborate.
Don't pipe ls! https://mywiki.wooledge.org/ParsingLs . This is what globbing is for.
I usually detox (https://linux.die.net/man/1/detox) my FS so I don't have to worry about these subtleties.
and yet you write an article that others might read, such that it becomes their worry instead? Nice.
sed | sh; cmd $(cmd) is harmful, see comment https://news.ycombinator.com/item?id=27861635
I usually detox (https://linux.die.net/man/1/detox) my FS so I don't have to worry about these subtleties.
xargs -P <numprocs> will run commands in parallel until they're all done. That's why I still break it out.
"I love xargs -L. It’s really great for grouping lines. No other program does it."
Ah ?
╰─○ seq 10 | xargs -L 3
1 2 3
4 5 6
7 8 9
10
╰─○ seq 10 | paste -d\ - - -
1 2 3
4 5 6
7 8 9
10
I think you're wrong .
Maybe! I can't repro it locally, but others have talked about this
$ seq 10 | paste -d\ - - -
1 2
3 4
5 6
7 8
9 10
$ seq 10 | paste -d\ - - - -
1 2-3
4 5-6
7 8-9
10 -
$ paste --version
paste (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David M. Ihnat and David MacKenzie.
Hi Tyler , my version of paste is the same "paste (GNU coreutils) 8.32"
Be sure to type the command correctly
There are two spaces after the backslah '\' !
$ seq 10 | paste -d\ - - -
1 2 3
4 5 6
7 8 9
10
or this is working as well
$ seq 10 | paste -d' ' - - -
1 2 3
4 5 6
7 8 9
10
Ah, that worked thanks for teaching me, this is great, I've updated and given you credit. I think substack might be eating the double space as there is only one space after the slash above.
You really misunderstand the -I parameter. In your example of "echo seq 10 | xargs -IX X", the second X has to be a proper command and it is not substituted (i.e. you don't get 'seq 10' there). So you are trying to start the X window manager, which obviously doesn't work.
Perhaps re-reading the documentation of xargs might be in order. Perhaps don't fulminate against tools you don't understand.
My point is that -I has such subtle, easily misunderstood behavior.
-I looks like a general purpose string replacer at first glance, but it's actually a more subtle special case one.
Spoken like someone who's never hit the command length limit.
If you're worried about rm $(..), then the sed | bash trick works perfectly fine.
Unless there are spaces in filenames.
That's an easy fix, sed 's/.*/rm "&"/'.
Or just detox the filesystem.
no, just dont do this, please.