Operating System - HP-UX
1832903 Members
2604 Online
110048 Solutions
New Discussion

a problem about find command

 
lin.chen
Frequent Advisor

a problem about find command

I use "find" command to search files in /tmp,
but I do not want to search in /tmp/test.
how can i do,thanks!
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: a problem about find command

Hi Lin:

# find /tmp -type f ! -path "/tmp/test/*"

This will recursively search '/tmp' returning all files but those in '/tmp/test'.

Regards!

...JRF...
Sandman!
Honored Contributor

Re: a problem about find command

find /tmp -type f ! \( -path "/tmp/test/*" -o -path "/tmp/another_dir/*" \)
Biswajit Tripathy
Honored Contributor

Re: a problem about find command


find /tmp -name 'XYZ' | grep -v '^\/tmp\/test'

Replace XYZ with the filename you want to search.
Use wildcard if reqd (i.e use 'a*' for finding files starting with 'a', note the single quote while using wildcard).

Searching for a string STRING in those files, use:

grep STRING `find /tmp -name 'XYZ' | grep -v '^\/tmp\/test'`

- Biswajit
:-)
Senthil Prabu.S_1
Trusted Contributor

Re: a problem about find command

Hi,
The exact switch to use with find command to exclude directories is;

find /tmp -name test-prune -o -print

where,

-prune = Does not examine any directories or files in the directory structure below the pattern just matched


HTH,
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.