Is there anyway to tell /usr/bin/find to blacklist a certain directory by absolute location. I'm using find (GNU findutils) 4.4.2.

find . -type f -not -path '*/media/*'

I would expect this never to traverse a through anything within a path named /media/. However, this clearly isn't the case. Reading the docs I see the answer is in -prune.

find . -path '*/media/*' -prune | grep media

However, that still returns stuff

./media/.listing
./media/ChromeImageGallery
./media/WheelsTV
./media/AutoBuilder4-Data

How come even with -prune find is returning stuff in the /media/ subdirectory?

link|improve this question

61% accept rate
feedback

1 Answer

up vote 1 down vote accepted

Give this a try:

find . -path '*/media/*' -prune -o -print

It will output media but not anything under it.

The following will completely eliminate media:

find . -name 'media' -prune -o -print
link|improve this answer
Awesome well done. – Evan Carroll Mar 1 '11 at 19:16
@EvanCarroll: Note that for more complex expressions, you may need to group parts of them using \( and \). See the EXAMPLES section of man find for more information. – Dennis Williamson Mar 1 '11 at 19:20
feedback

Your Answer

 
or
required, but never shown

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