Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Guys, I'm using the find command on a Mac to search for a folder called 'test1'. Now 'test1' folder could be present in the '.Trash' folder also. How do I exclude the '.Trash' folder from getting reported in search results or basically any folder I wish to exclude?

$ find $HOME -name test1 -type d




I want the result to be just



I used grep:

find $HOME -name test1 -type d | grep -v '.Trash'

to filter out the .Trash result, but I'm interested in knowing if using 'find' alone achieves the same results.

share|improve this question
up vote 9 down vote accepted

find $HOME -path $HOME/.Trash -prune -o -name test1 -type d -print

Edited to add -print -- that avoids the spurious printing of .Trash.

share|improve this answer

Use the -prune primary:

find $HOME -name .Trash -prune -o -name test1 -type d


That will include .Trash in the output. To fix that:

find $HOME -name .Trash -prune -o \( -name test -type d -print \)
share|improve this answer
Using -name will also excluded results in directories named .Trash which are not in the root of the user's home directory. – herrtodd May 12 '11 at 23:18
True. I went with smokingun's use of grep -v '.Trash' (should be '\.Trash') as an indication that .Trash might appear elsewhere. I think yours is the better answer, though. – garyjohn May 12 '11 at 23:25

Your Answer


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.