Operating System - Linux
1754019 Members
7826 Online
108811 Solutions
New Discussion юеВ

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 2
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