upstream | xargs …xargs reads items from standard input (separated by whitespace by default) and runs a command, passing the items as arguments. The classic companion to find, but also useful with ls, grep, cat, or any pipeline that produces a list.
upstream | xargs [options] command [initial-args]
By default xargs splits input on any whitespace (spaces, tabs, newlines), and quotes are stripped. This breaks for filenames with spaces.
The standard fix: use find ... -print0 together with xargs -0 so items are separated by NUL bytes (which can't appear in filenames):
find . -name "*.tmp" -print0 | xargs -0 rm
By default, xargs appends input items to the end of the command. Use -I {} to place the input wherever you want:
| default | ... | xargs mv -t /dest/ — items go at the end |
| -I {} | ... | xargs -I {} mv {} /dest/{}.bak — items go where {} appears |
With -I, xargs runs the command once per item, not in batches.
-P N runs up to N processes at once. -P 0 means "as many as possible (no limit)". Pair with -n to control how many items each process gets:
find . -name "*.jpg" -print0 | xargs -0 -n 1 -P 4 convert -resize 50%
| Safe rm by find | find . -name "*.bak" -print0 | xargs -0 rm |
| Grep many files | find . -name "*.py" -print0 | xargs -0 grep "TODO" |
| Parallel image resize | find . -maxdepth 1 -name '*.jpg' -print0 | xargs -0 -n 1 -P 4 mogrify -resize 800x600 |
| Move with -I | find . -name "*.log" -print0 | xargs -0 -I {} mv {} /archive/ |
| Confirm each | find . -name "*.old" -print0 | xargs -0 -p rm |
| Don't run if empty | find . -name "*.tmp" -print0 | xargs -0 -r rm |
• Always pair -print0 with -0 when piping from find. This is the only safe way to handle arbitrary filenames.
• Use -r (or --no-run-if-empty) to avoid running the command at all when the input is empty. GNU xargs only; not in POSIX.
• Test runs with -t (trace, prints the command before running it) or -p (prompt before each).
• xargs -L 1 runs the command once per line of input (instead of per whitespace-separated token).
• If the command has its own arguments that should always be present, put them right after the command name: xargs rm -rf applies -rf to every batch.
This is an educational tool. The commands it builds are real — they will do exactly what you tell them to. Some flags are destructive (deletion, overwriting, forced operations) and even non-destructive options can cause data loss or system trouble in the wrong circumstances.
• Always review the generated command before running it.
• Test on disposable files and directories first.
• If you do not understand what a flag does, look it up in the official manual page (man command).
The author of these pages is not responsible for any damage, data loss, or other consequences resulting from commands generated, copied, or run from this site. Use at your own risk.
⚠ These tools build real shell commands. Review every command before running it. The author is not responsible for any damage, data loss, or other consequences resulting from commands generated, copied, or run from this site. Use at your own risk.
Send comments and bug reports to chris@chrisspackman.com.
Version 0.2.0 — Last updated: 2026-05-26
This page is Copyright © 2026
Chris Spackman <chris@chrisspackman.com>.
This web site developed entirely on GNU/Linux with Free / Open Source Software.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.