Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'd like to cast find on a dir excluding a subdir of its. I've found two very different examples on google and since they both do not even attempt to work, I assume either under OSX things something differs, or I'm doing something strange.

I'd like to do:

find here/ -name '*.xxx' -BUTNOT here/there/ -exec stuff {} \;

Using the examples I tried I either get an error, or 0 matches, or all matches.

I might need to exclude more than one subdir.

share|improve this question
up vote 3 down vote accepted

Unfortunately I don't have OS X available right now, but at least in Linux this works:

find . -name \*.xxx -o -path ./path/to/exclude -prune ...

To prune more than one dir, repeat the whole pattern -o -path ... -prune:

find . -name \*.xxx -o -path ./path/to/exclude1 -prune -o -path ./path/to/exclude2 -prune ...
share|improve this answer
Oooh initially it didn't work, then I noticed a problem was the trailing / in the path to exclude (while it causes no problems in the patch to search). Thanks! – o0'. Feb 17 '11 at 17:47

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.