LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   *BSD (https://www.linuxquestions.org/questions/%2Absd-17/)
-   -   "find" exclude file/folder from search (https://www.linuxquestions.org/questions/%2Absd-17/find-exclude-file-folder-from-search-718648/)

da1 04-12-2009 03:19 PM

"find" exclude file/folder from search
 
Hello,


Here's a nice (idiotic) question.

How to exclude a file/folder from search ?

Case:
We have a standard / .
In / there exists /mnt that has several folders, each pointing to different hdd's. If one wants to search the / partition but not descend into /mnt, what would the corect command be ?

Tryed some combination of "-prune, -path" but faile mizerably.



Thx.

colucix 04-12-2009 03:30 PM

Code:

find / -wholename /mnt -prune -o -name my_file -print
See this post for a detailed explanation.

da1 04-12-2009 03:41 PM

thx...

rocket357 04-12-2009 04:08 PM

-xdev, or, if you find it more readable, -mount.

Note, this is by side-effect that it doesn't descend into directories in /mnt. What -xdev/-mount do is stop "find" from descending into directories on other filesystems. If you have multiple mount points, you could:

# for dir in `df -l | grep / | cut -d'%' -f2`; do find $dir <options> -xdev; done

It'll launch multiple "find" processes, but it'll effectively exclude all remote filesystems.

You also could figure out a way to negate -fstype arg to "find", but I couldn't seem to locate anything on that.


All times are GMT -5. The time now is 10:49 PM.