What is the difference between `-exec cmd {} \;`, `-exec cmd {} +` and `-delete`?
IntermediateConceptfind, xargs, jq and yq
Answer
-exec cmd {} \;runscmdonce per file: slow for thousands of files.-exec cmd {} +passes as many files as fit into one command line, likexargs: fast.-deleteremoves files internally with no process at all, and implies-depth.
find /var/log/app -name '*.log' -mtime +7 -exec gzip -- {} +
find /var/log/app -name '*.gz' -mtime +30 -delete
find /srv/app/releases -mindepth 1 -maxdepth 1 -type d -mtime +10 -exec rm -rf -- {} +
Put -delete last: find . -delete -name '*.tmp' deletes everything before the name test is applied.
More on find, xargs, jq and yq
What are the most useful `find` predicates for operations work?BeginnerHow does `find` evaluate `-o` (OR) and why do you need parentheses?AdvancedWhat does `xargs` do, and which flags matter?IntermediateWhy is `find | xargs rm` dangerous and what is the safe form?IntermediateWhat is `jq` and what are the filters you use every day?BeginnerHow do you pass shell variables into `jq` safely?Intermediate