xargs Dry Run on Linux: Safe Pipelines Before rm or Overwrite

xargs dry run - custom-xargs54-featured.png

xargs dry run searches spike when a find … | xargs rm pipeline almost went wrong. Learn xargs pipelines first; this page is the safety layer.

Print the command

xargs -t echoes each invocation to stderr before it runs.

bashtrace
printf 'a\nb\n' | xargs -t -I{} echo file {}
-t
trace

Echo instead of act

Swap the command for echo to see arguments.

bashpreview
find /var/log -name '*.gz' -mtime +30 -print | xargs echo rm -f
echo
preview

Confirm each batch

xargs -p prompts once per line of input (interactive).

WarningDo not use -p in cron — only for interactive shells.
-p
prompt

Limit width

xargs -n 1 runs one file at a time — easier to audit and recover.

bashone
find ./work -type f -name '*.tmp' -print | xargs -n 1 -t rm -f
-n 1
limit

Quick Reference

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.