Vijay
Vijay

Reputation: 67301

unix find command

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

Upvotes: 0

Views: 1314

Answers (3)

bhagya
bhagya

Reputation: 1

$ 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

Upvotes: -2

Vijay
Vijay

Reputation: 67301

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

this should be the answer. thanks Dave.

Upvotes: 2

brian-brazil
brian-brazil

Reputation: 34172

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" \)

Upvotes: 3

Related Questions