Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

So I'm trying to find all the mercurial repositories in my home directory

$ find ~ -name ".hg" -or -name ".git"

This works fine, but it finds a lot in the ~/.local/share/Trash subdirectory

How do I make it ignore these? Obviously there's grep -v, but it would be better not to search Trash at all.

share|improve this question
up vote 3 down vote accepted

You can use the -prune option this way:

find ~ -path '*Trash*' -prune -or -name ".hg" -or -name ".git"
share|improve this answer
awesome thanks! – John Lawrence Aspden Mar 27 '11 at 16:32
This really works? For me it doesn't prune all the different files with the string Trash in it; also this is looking for files with the exact name ".hg"; shouldn't it be something like *.hg? – arrange Mar 27 '11 at 16:48
@arrange, I take the example from the user asking the question, and modified that. And, obviously, it works for me that have done some tests. – enzotib Mar 27 '11 at 17:00

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.