Operating System - HP-UX
1835608 Members
2847 Online
110079 Solutions
New Discussion

Re: Running the "find" command, but want to exclude certain dirs

 
SOLVED
Go to solution
john guardian
Super Advisor

Running the "find" command, but want to exclude certain dirs

Hi. Is there a way to use the find command to get a general listing of ALL files on the system while EXCLUDING certain directories such as "/usr/local"?
5 REPLIES 5
Jonathan Fife
Honored Contributor
Solution

Re: Running the "find" command, but want to exclude certain dirs

You could use the prune flag, but it doesn't let you specify the full path of the directory, just the directory name. In other words, any directory named "local" will be excluded.

Syntax:
find / \( -name local -a -type d -prune \) -o \( -print \)

I would more likely just pipe the output of find through grep and -v the directories I didn't want to see.

find / -print | grep -v ^/usr/local

HTH
Decay is inherent in all compounded things. Strive on with diligence
A. Clay Stephenson
Acclaimed Contributor

Re: Running the "find" command, but want to exclude certain dirs

To exclude /usr/local and /etc/lp starting from / (which is normally not a good idea):

find / ! \( -path '/usr/local/*' -o -path '/etc/lp/*' \)

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

Re: Running the "find" command, but want to exclude certain dirs

Hi JOhn:

# find / -type f ! -path "/usr/local/*"

...should meet your needs. This will look for ALL FILES on ALL mountpoints, but skip the '/usr/local/*' directory.

Regards!

...JRF...
Robert-Jan Goossens
Honored Contributor

Re: Running the "find" command, but want to exclude certain dirs

John,

check this find discussion.

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=975461

Regards,
Robert-Jan
Sandman!
Honored Contributor

Re: Running the "find" command, but want to exclude certain dirs

For example if you wanted to exclude "/usr/local", "/etc" and "/sbin" dirs then...

# find / \( -path "/usr/local" -o -path "/sbin" -o -path "/etc" \) -prune -o -type f -print

cheers!