man.lsPlain-English help for Unix commands

xargs Build commands from standard input

Reads items from standard input and runs another command with them as arguments. Use it when a command takes file names as arguments but you have them as a list, for example the output of find.

Synopsis

xargs [OPTION]... [COMMAND [ARG]...]
find ... -print0 | xargs -0 COMMAND

Common options

Option or formWhat it does
-0, --nullExpect input items separated by NUL characters instead of whitespace. Pair it with find -print0 so odd file names are safe
-I replstrRun the command once per input line, replacing replstr (often {}) with that line wherever it appears in the command
-n numberPass at most number arguments to each run of the command. -n 1 runs it once per item
-P maxprocsRun up to maxprocs commands at the same time. -P 0 uses as many as possible
-pAsk for confirmation before each run
-tPrint each command to standard error before running it
-r, --no-run-if-emptyDo not run the command when the input is empty. Needed on GNU/Linux, accepted but not needed on macOS
-E eofstrStop reading input when a line equals eofstr

Examples

Pass lines of input as arguments
printf 'a.txt\nb.txt\n' | xargs touch
Run the command once per item
printf '1\n2\n3\n' | xargs -n 1 echo item
item 1
item 2
item 3
Count lines in every text file found
find docs -name '*.md' -print0 | xargs -0 wc -l
Use a placeholder to put each name in the middle of a command
find photos -name '*.jpg' | xargs -I{} cp {} {}.bak
Show details for every file find lists
find docs -type f -print0 | xargs -0 ls -l
Compress many files, four at a time
find . -name '*.log' -print0 | xargs -0 -P 4 gzip

Notes

See also

Last reviewed 2026-10-07.