1843953 Members
2161 Online
110226 Solutions
New Discussion

Re: find command

 
SOLVED
Go to solution
alana duvall_1
Occasional Contributor

find command

how can I use the find the command to search the entire server but exclude the search in two directories. These two directories have temporary, output, and log files that I do not want included in the search results.

Thanks
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: find command

First, I would not do a find from / because that is a huge resource hog but you should be able to do something like this:

find . ! \( -path './adm*' -o -path './TT_DB* \)

This would exclude the ./adm directory and the
./TT_DB directory.

Man find for details.

If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: find command

Hi:

Consider this example, which searches /tmp but does not descend the /tmp/dummy directory:

# find /tmp \( -name "f*" -a ! -path "/tmp/dummy/*" \)

This will return all files in '/tmp/' but *not* 'tmp/dummy/' that begin with the letter "f". Note the quotes so that the shell doesn't expand the expresssion.

Regards!

...JRF...
Alan Riggs
Honored Contributor

Re: find command

As noted by others, the find command from / is a resource monster. In order to search the entire server for files name *foo* I recommend:

du -a / | grep -i foo

This is faster, less resource intensive, and has all the power of grep for matching you filename(s). You can use grep -v to eliminmate your temp and logfile paths, for you can do something like:

for PATH in $(ls / |egrep -v "temp_dir|log_dir")
do
du -a $PATH | grep -i FILENAME
done
Bill Hassell
Honored Contributor

Re: find command

find is so bad that I wrapper the command to check if / has been specified and issue a very nasty message for users that try this on a production machine. Files are not often 'lost' and application programs are not scattered all over the system.

For instance, why look for core files to purge when you can prevent them completely with ulimit -c 0? And if an application was installed but did not document where it was stored, there's no need to look in /stand or /etc or /dev, but instead look in /opt, /usr/contrib/bin and /usr/local/bin using ls, not find.


Bill Hassell, sysadmin