I would like to search for files that would not match 2 -name conditions. I can do it like so :
find /media/d/ -type f -size +50M ! -name "*deb" ! -name "*vmdk"
and this will yield proper result but can I join these 2 condition with OR somehow ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
You can do this using a negated -regex, too:-
find ./ ! -regex '.*(deb|vmdk)$'
Method 3
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
Method 4
You can use regular expressions as in:
find /media/d -type f -size +50M ! -regex '(.*deb|.*vmdk)'
Backslash is the escape character; . matches a single character, and * serves to match the previous character zero or more times, so .* means match zero or more characters.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0