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

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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on find, xargs, jq and yq