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?


Add a ! (not) before the expression:

sudo find path ! -name '*xyz*'
  • 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 – notablytipsy 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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