Interview Prep/Shell Scripting/find, xargs, jq and yq

Why is `find | xargs rm` dangerous and what is the safe form?

IntermediateConceptfind, xargs, jq and yq
Answer

Default xargs splits on spaces and newlines, so /data/old report.csv becomes two arguments, and a crafted name like x /etc/passwd could delete something unrelated. With empty input, GNU xargs still runs rm once with no arguments (harmless for rm, but not for every command).

find /data -name '*.csv' -mtime +30 -print0 | xargs -0 -r rm -f --
# or simply
find /data -name '*.csv' -mtime +30 -delete

-- stops rm from treating a file named -rf as options.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on find, xargs, jq and yq