General
cancel
Showing results for 
Search instead for 
Did you mean: 

how to exclude a subdir in find search

SOLVED
Go to solution
Maaz
Valued Contributor

how to exclude a subdir in find search

I have to search in the /home, but in every user's home directory there is a directory named "drives", and I dont want to search in the directory named "drives"

I tried, the following but failed

find /home -not -name "drives" -name "abc.txt"
find /home -not -wholename "drives" -name "abc.txt"

please help

Regards
2 REPLIES
Dennis Handly
Acclaimed Contributor
Solution

Re: how to exclude a subdir in find search

Here are some examples in the HP-UX world using -prune. (I would have thought being linux, it would be easy. :-)

find /home \( -name "drives" -prune -o ! -name "drives" \) -name "abc.txt"

If drives is small you could use ! -path "*drives*".

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1276654
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1303248
Maaz
Valued Contributor

Re: how to exclude a subdir in find search

Thanks Dear Dennis Handly, for such a CCC(cool, crunchy, crispy) reply ;)

Regards