Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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! –  Lohoris Feb 17 '11 at 17:47

Your Answer

 
discard

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.