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
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
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" \)
find <some options> ! -name "dontfile.txt"
this should be the answer. thanks Dave.
$ 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
$