See below example:
$ ls -1p
appledir/
applefile
orangedir/
orangefile
$ find . -type f -name apple\*
./applefile
$ find . -type f -name orange\*
./orangefile
$ find . -type f -name apple\* -o -name orange\*
./applefile
./orangedir
./orangefile
$ find . -type f \( -name apple\* -o -name orange\* \)
./applefile
./orangefile
$
I was surprised to discover I needed the parentheses for this to work as expected; apparently I haven't internalized the rule of precedence by which find evaluates its arguments.
How can I easily predict when I will and when I will not need to use parentheses to explicitly group find primaries?
Put another way, what are the rules by which I can imagine find inserting parentheses into the commands I give it, which will allow me to accurately predict how it will evaluate ungrouped expressions?
findwith multiple-nameand-execexecutes only the last matches of-name– Stéphane Chazelas Sep 28 '16 at 13:28