Shell // Command Composition
xargs
Turn any output into arguments — and run commands in bulk.
$ [command] | xargs [OPTIONS] [command]
Key Flags
-I {}Placeholder — insert each arg at {} in the command -P NRun N commands in parallel -n NPass N arguments at a time -0Null-delimited input (safe for filenames with spaces) -tPrint each command before running (debug mode) -rDon't run command if input is empty
Examples
$ find . -name "*.tmp" -print0 | xargs -0 rm -f
# Deletes every .tmp file — -print0/-0 handles spaces in names
Null delimiter is the safe way to handle filenames
$ cat urls.txt | xargs -P4 -I{} curl -sO {}
# Downloads all URLs 4 at a time, in parallel
-P4 runs 4 curl processes simultaneously — massive speedup
$ find . -name "*.log" | xargs -I{} mv {} archive/
archive/app.log archive/error.log archive/access.log
Move every matched file — replaces a for loop with one line