6

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?

2 Answers 2

9

Add a ! (not) before the expression:

sudo find path ! -name '*xyz*'
4
  • 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, 2012 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 Jul 16, 2012 at 7:50
  • 1
    You probably need to quote the !, i.e. use \!.
    – Thor
    Jul 16, 2012 at 8:41
  • I tried it as is and it wasn't necessary to use \!. Aug 13, 2012 at 0:43
3

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .