Exclude directory in find
find . -name 'foo-exclude-me' -prune -o -name 'foo*' -print
With no -print
, the implicit default action applies to every match, even pruned ones. The explicit -print
applies only under the specified conditions, which are -name 'foo*'
only in the else branch of -name 'foo-exclude-me'
.
Generally speaking, use an explicit -print
whenever you're doing something more complex than a conjunction of predicates.
Your second attempt with ! -path './foo-exclude-me/*'
didn't work because ./foo-exclude-me
doesn't match ./foo-exclude-me/*
(no trailing /
). Adding ! -path ./foo-exclude-me
would work.