Find Command Exclusions – Exclude proc and sys Folders from Search

command linefind

I wanted to execute a script that picks out a random directory path:

find / -type d | shuf -n1 

Unfortunately I get error messages about the prohibition of entering certain directories.

How can I exclude a directory from the search with find ?

Best Answer

To exclude specific paths, on Linux:

find / -path /sys -prune -o -path /proc -prune -o -type d

Another approach is to tell find not to recurse under different filesystems.

find / -xdev -type d

You could also use locate to query a database of file names (usually updated nightly, you could also update it manually using updatedb) instead of the live system.

locate '*' | shuf -n 1
Related Question