xargs flags & options
-I
Replace a placeholder string with each input line. Commonly uses {}.
find . -name "*.bak" | xargs -I {} mv {} {}.old
cat urls.txt | xargs -I {} curl -s {}
-n
Use at most N arguments per command invocation.
echo "a b c d e f" | xargs -n 2
-P
Run up to N commands in parallel.
cat urls.txt | xargs -P 4 -I {} curl -s {}
-0, --null
Input items are separated by null character instead of whitespace. Pairs with find -print0.
find . -name "*.tmp" -print0 | xargs -0 rm
-t, --verbose
Print each command before executing it.
echo "a b c" | xargs -t echo
-p, --interactive
Prompt before executing each command.
find . -name "*.log" | xargs -p rm
-r, --no-run-if-empty
Don't run the command if stdin is empty. Default on GNU, needed on BSD.
echo "" | xargs -r echo "not empty"
-L
Use at most N input lines per command invocation.
cat hosts.txt | xargs -L 1 ssh -o ConnectTimeout=2