xargs
Turn a list into arguments.
Some commands don't read from a pipe. RM, MK dir, and touch want names as arguments, not as input. Xargs builds a bridge. It takes a list from a pipe, and turns it into arguments.

- Some commands ignore pipes
- They want arguments
- xargs builds the bridge
From a list to arguments
Here's a file with three folder names. Cat prints them. Piping them straight into MK dir wouldn't work. But through xargs, MK dir receives all three names as arguments, and creates them.
cat months.txt jan feb mar cat months.txt | xargs mkdir ls -d jan feb mar feb jan mar
With find
Xargs is often used with find. Here, find lists every log file in our home, and xargs passes them all to WC dash L, which counts the lines in each. One command, run on many files.
find . -name "*.log" | xargs wc -l 60 ./logs/old.log 60 ./logs/server.log 120 total
Careful with spaces
Remember the trouble with spaces in names? Xargs splits on spaces too. So a file called my notes would become two arguments. The safe version is find dash print zero, with xargs dash zero. And for deleting, find's own dash delete is usually simplest.
| key | value |
|---|---|
| cmd | xargs cmd2 | list to arguments |
| find | xargs | act on many files |
| Spaces | can break names |
| Safe | find -print0 | xargs -0 |
Summary
Xargs turns lines from a pipe into arguments, for commands that don't read input. Next, simple patterns, for smarter searches.
Key takeaways- ... | xargs cmd
- Great with find
- -print0 / -0 for spaces