23 Comments

$ touch '--no-preserve-root / foo' 'foo'

$ rm $(ls | grep foo)

Expand full comment

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)

Expand full comment

$ 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.

Expand full comment

None of this is good advice. You should use the find command.

Expand full comment

Don't pipe ls! https://mywiki.wooledge.org/ParsingLs . This is what globbing is for.

Expand full comment

sed | sh; cmd $(cmd) is harmful, see comment https://news.ycombinator.com/item?id=27861635

Expand full comment

xargs -P <numprocs> will run commands in parallel until they're all done. That's why I still break it out.

Expand full comment

"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 .

Expand full comment

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.

Expand full comment

Spoken like someone who's never hit the command length limit.

Expand full comment