views:

126

answers:

3

how to use the find command to find files/directories which are not matching the pattern. for eg:

find <some options > -name "dontfile.txt"

should give me output of all the find whose file name is not dontfile.txt

+3  A: 

Use the -not operator:

find <some options > -not -name "dontfile.txt"

You may need to add parenthesis to get the desired effect, depending on how complex the rest of the command is:

find <some options > \( -not -name "dontfile.txt" \)
not sure whether this will work.i am working on hpux and its not accepting the `-not` option
Vijay Sarathi
`find: bad option -not`
Vijay Sarathi
On HPUX, use `!`. http://www.informatik.uni-frankfurt.de/doc/man/hpux/find.1.html
outis
Try ! instead of -not - i.e. find <some options> ! -name "dontfile.txt"
Dave Webb
+2  A: 
find <some options> ! -name "dontfile.txt"

this should be the answer. thanks Dave.

Vijay Sarathi
A: 

$ ls -ltr

total 0

-rw-r--r-- 1 mraj baudba 0 Nov 18 05:35 d.txt

-rw-r--r-- 1 mraj baudba 0 Nov 18 05:35 c.txt

-rw-r--r-- 1 mraj baudba 0 Nov 18 05:35 b.txt

-rw-r--r-- 1 mraj baudba 0 Nov 18 05:35 a.txt

$ find . -name "a.txt" -print

./a.txt

$ find . ! -name "a.txt" -print

.

./b.txt

./c.txt

./d.txt

$

Unix find command with examples

bhagya
@bhagya..this is same as the above one ..i cannot find any difference.
Vijay Sarathi