How does `find` evaluate `-o` (OR) and why do you need parentheses?
AdvancedConceptfind, xargs, jq and yq
Answer
Predicates are joined by an implicit -a (AND), which binds tighter than -o. Actions apply only to the branch they are in.
find . -name '*.log' -o -name '*.tmp' -delete # deletes only *.tmp!
find . \( -name '*.log' -o -name '*.tmp' \) -delete # deletes both
# Skip directories with -prune
find . -path ./node_modules -prune -o -name '*.js' -print
Escape the parentheses so the shell does not interpret them, and keep spaces around them. Without an explicit -print, the -prune example also prints ./node_modules.
More on find, xargs, jq and yq
What are the most useful `find` predicates for operations work?BeginnerWhat is the difference between `-exec cmd {} \;`, `-exec cmd {} +` and `-delete`?IntermediateWhat 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