find, excluding dir, not descending into dir, AND using maxdepth and mindepth
Posted
by
user1680819
on Stack Overflow
See other posts from Stack Overflow
or by user1680819
Published on 2012-09-18T16:51:51Z
Indexed on
2012/09/26
3:37 UTC
Read the original article
Hit count: 168
This is RHEL 5.6 and GNU find 4.2.27.
I am trying to exclude a directory from find, and want to make sure that directory isn't descended into. I've seen plenty of posts saying -prune will do this - and it does. I can run this command:
find . -type d -name "./.snapshot*" -prune -o -print
and it works. I run it through strace and verify it is NOT descending into .snapshot.
I also want to find directories ONLY at a certain level. I can use mindepth and maxdepth to do this:
find . -maxdepth 8 -mindepth 8 -type d
and it gives me all the dirs 8 levels down, including what's in .snapshot.
If I combine the prune and mindepth and maxdepth options:
find . -maxdepth 8 -mindepth 8 -type d \( -path "./.snapshot/*" -prune -o -print \)
the output is right - I see all the dirs 8 levels down except for what's in .snapshot, but if I run that find through strace, I see that .snapshot is still being descended into - to levels 1 through 8.
I've tried a variety of different combinations, moving the precedence parens around, reording expression components - everything that yields the right output still descends into .snapshot.
I see in the man page that -prune doesn't work with -depth, but doesn't say anything about mindepth and maxdepth.
Can anyone offer any advice?
Thanks... Bill
© Stack Overflow or respective owner