I see that the find command does not descend into subdirectories when you're using the -prune option. How do I tell find to recurse into the sub directories, but also ignore some stuff?

Specifically, I want to search the /var/lib/foo directory, but exclude any directories with the name .snapshot/.

sudo find /var/lib/foo -prune -name '.snapshot'

With the above, it properly ignores .snapshot, but doesn't go into the sub dirs. FYI, I'm working in bash on a CentOS 6.3 host.

1 Answer 1


You need to do:

sudo find /var/lib/foo -name '.snapshot' -prune -o -print

it will print whatever is not named ".snapshot", and if ".snapshot" is a directory it will also not descend into it.

why ? because "-prune" is an action (as '-print' is also another action), doing nothing except preventing to go further down in the subdir. And it always return "true", so here, ( -name ... -prune ) is true if and only if the file or dir is named "...", and you you want everything else, hence the -o ( -print ).

  • I found this nice so answer by @Laurence Gonsalves which explains it so much better (including a nice warning about not adding the -print) Jan 16, 2013 at 16:18
  • 1
    Works perfect, thanks Olivier. I tend to forget the ordering of things with the find command, such as actions.
    – Banjer
    Jan 16, 2013 at 18:01
  • parenthesis also helps : find /someplace \( some tests [and actions] \) -o \( some other tests [and actions] \) , with possibility of multiple layers of parenthesis. Jan 16, 2013 at 18:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .