Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

So when you want to search for a file with a filename containing the string xyz from a directory to all depths, you write

sudo find path -name '*xyz*'

How do I find all files without the string xyz?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

Add a ! (not) before the expression:

sudo find path ! -name '*xyz*'
share|improve this answer
    
Negation is also particularly useful when searching for permissions that are not set correctly -e.g. find <path> -type f ! -perm -444 or find <path> -type d ! -perm -111. For more on find see pixelbeat.org/cmdline.html. –  user76204 Jul 15 '12 at 19:19
    
I think I'd tried this and it didn't work. Maybe I'd put the '!' in a different place? Anyway, this worked perfectly. And thanks for the tip, @Mik –  asymptotically Jul 16 '12 at 7:50
1  
You probably need to quote the !, i.e. use \!. –  Thor Jul 16 '12 at 8:41
    
I tried it as is and it wasn't necessary to use \!. –  John S Gruber Aug 13 '12 at 0:43

To search for files not containing '*xyz*' do:

sudo find path -type f -not -name '*xyz*'

To search for paths (files and directories) not containing '*xyz*' do:

sudo find path -not -path '*xyz*'

To search case-insensitively prepend name or path with i, i.e. -iname or -ipath.

share|improve this answer
1  
Perfect! Thanks! –  asymptotically Jul 16 '12 at 7:48

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.