Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 7 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 – 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
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
Perfect! Thanks! – asymptotically Jul 16 '12 at 7:48

Your Answer


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.