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.

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?

share|improve this question

1 Answer 1

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
share|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

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.