Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

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 ).

share|improve this answer
I found this nice so answer by @Laurence Gonsalves which explains it so much better (including a nice warning about not adding the -print) – Olivier Dulac Jan 16 '13 at 16:18
Works perfect, thanks Olivier. I tend to forget the ordering of things with the find command, such as actions. – Banjer Jan 16 '13 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. – Olivier Dulac Jan 16 '13 at 18:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.