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 a way to perform a find command on my whole computer, excluding external hard drives? I've been using the find command to search for junk left over from uninstalled software, like (from the top of the directory):

sudo find -iname . "*badexample*"

I'm confident there's nothing I'm looking for on my external drive. I suppose I could simply disconnect it before doing the find, but I'm curious how I might specify such an exclusion with bash. I'm also a little confused about where the external drive is located in the directory as well; /Volumes contains an alias that points to the drive, but it looks (using Get Info in Finder) like it points to itself.

share|improve this question
up vote 1 down vote accepted

From the man page:

-mount Don’t descend directories on other filesystems.

Use this to see it yourself:

man find | less -p "-mount"

Of course this will prevent find from descending into ANY other filesystems, not just the one USB drive you are attempting to exclude.

Alternatively, you can do this. It won't save time and it WILL still search the USB drive, but will not display those particular results:

find / -name "badpattern" | grep -v "/path/to/USB_DRIVE"

share|improve this answer
I had to do a little digging (version of find on my computer uses -x instead of -mount), but this worked. Excellent! Thank you! – ivan Oct 3 '12 at 22:38
Many Linux programs use -x (like du for example). The find command also allows -xdev in addition to -mount. They both do the same thing. – UtahJarhead Oct 4 '12 at 12:24

You must log in to answer this question.

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