Part of Linux Commands Cheat Sheet

Xargs allows you to build and execute commands from standard input.

For those commands accepting pipe (like grep), you can do this:

ls | grep a

But for those commands only accept command line options (like rm), you can't:

Content of to-be-deleted.txt:


cat to-be-deleted.txt | rm

Nothing happens but an error: "rm: missing operand".

That's where xargs comes into play:

cat to-be-deleted.txt | xargs rm

# or
xargs -a blacklist.txt rm

Split args into groups

# -t for verbose, every command executed will be print
xargs -a to-be-deleted.txt -tL 1 rm

Without -L 1, the output will be:

rm a.txt b.txt

With -L 1, the output will be:

rm a.txt
rm b.txt


Xargs Command in Linux | Linuxize