Sample Header Ad - 728x90

Why is looping over find's output bad practice?

220 votes
8 answers
44353 views
This question is inspired by _Why is using a shell loop to process text considered bad practice ?_ I see these constructs for file in find . -type f -name ...; do smth with ${file}; done and for dir in $(find . -type d -name ...); do smth with ${dir}; done being used here almost on a daily basis even if some people take the time to comment on those posts explaining why this kind of stuff should be avoided... Seeing the number of such posts (and the fact that sometimes those comments are simply ignored) I thought I might as well ask a question: *Why is looping over find's output bad practice and what's the proper way to run one or more commands for each file name/path returned by find ?*
Asked by don_crissti (85483 rep)
Nov 7, 2016, 06:22 PM
Last activity: Apr 19, 2025, 09:44 AM