How to combine 2 -name conditions in find?

yes, you can:

find /media/d/ -type f -size +50M ! \( -name "*deb" -o -name "*vmdk" \)

Explanation from the POSIX spec:

! expression : Negation of a primary; the unary NOT operator.

( expression ): True if expression is true.

expression -o expression: Alternation of primaries; the OR operator. The second expression shall not be evaluated if the first expression is true.

Note that parenthesis, both opening and closing, are prefixed by a backslash (\) to prevent evaluation by the shell.


You can do this using a negated -regex, too:-

 find ./ ! -regex  '.*\(deb\|vmdk\)$'

You were close to a solution:

find /media/d/ -type f -size +50M -and ! -name "*deb" -and ! -name "*vmdk"

You can combine the following logic operators in any sequence:

-a   -and      - operator AND
-o   -or       - operator OR
!              - operator NOT

Tags:

Shell

Bash

Find