Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

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


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

share|improve this question
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .