Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

3 Answers 3

up vote 6 down vote accepted

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

 find ./ ! -regex  '.*\(deb\|vmdk\)$'
share|improve this answer
    
I don't think this works. –  Francesco Turco Oct 12 '12 at 13:51
    
Note that -regex is less portable than -name. –  jw013 Oct 12 '12 at 13:54
    
@FrancescoTurco: Yes, sorry, you're right. The regex needs to match the whole path.. Answer updated. –  Alex Leach Oct 13 '12 at 11:03
add comment

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.

share|improve this answer
    
Adding an explanation would make your answer better. –  N.N. Oct 12 '12 at 13:53
add comment

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.

share|improve this answer
    
Adding an explanation would make your answer better. –  N.N. Oct 12 '12 at 14:01
    
You're right. Added some explanations. –  Francesco Turco Oct 12 '12 at 14:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.