Build and execute commands from standard input.
medium risk
xargs reads items from stdin and passes them as arguments to a command. Handles the case where a command doesn't natively read from stdin. With -P, it runs multiple processes in parallel — a simple way to parallelize shell operations.
| Flag | Meaning |
|---|---|
-n --max-args | Max arguments per command invocation |
-I --replace | Replace placeholder string with each input item |
-P --max-procs | Run N processes in parallel |
-p --interactive | Prompt before each execution |
-0 --null | Input items are null-terminated (safe for filenames with spaces) |
find . -name '*.log' | xargs wc -lCount lines in all log files · explain & risk-check →cat pods.txt | xargs -I{} kubectl delete pod {}Delete pods listed in a file · explain & risk-check →find . -name '*.go' | xargs -P 4 gofmt -wFormat Go files in parallel · explain & risk-check →find . -name '*.tmp' -print0 | xargs -0 rm -fSafe deletion with null-separated filenames · explain & risk-check →Always use `find -print0 | xargs -0` when filenames might contain spaces or newlines — the default newline separator will cause silent failures.
Reference text is hand-written and may be incomplete — check man xargs for your version. Test destructive commands on a non-production system first.