Previous: Filesystems, Up: Finding Files



2.11 Combining Primaries With Operators

Operators build a complex expression from tests and actions. The operators are, in order of decreasing precedence:

( expr )
Force precedence. True if expr is true.
! expr
-not expr
True if expr is false.
expr1 expr2
expr1 -a expr2
expr1 -and expr2
And; expr2 is not evaluated if expr1 is false.
expr1 -o expr2
expr1 -or expr2
Or; expr2 is not evaluated if expr1 is true.
expr1 , expr2
List; both expr1 and expr2 are always evaluated. True if expr2 is true. The value of expr1 is discarded. This operator lets you do multiple independent operations on one traversal, without depending on whether other operations succeeded. The two operations expr1 and expr2 are not always fully independent, since expr1 might have side effects like touching or deleting files, or it might use -prune which would also affect expr2.

find searches the directory tree rooted at each file name by evaluating the expression from left to right, according to the rules of precedence, until the outcome is known (the left hand side is false for -and, true for -or), at which point find moves on to the next file name.

There are two other tests that can be useful in complex expressions:

— Test: -true

Always true.

— Test: -false

Always false.