Find files excluding a directory

You can use the -o flag as an OR condition with the find command.

The following command will output the contents of a [directory], excluding anything that matches the [path to ignore] (which can include wildcards).

find [directory] -path "[path to ignore]" -prune -o -print

If you pipe the results through grep, you can search for everything that matches the [pattern]. In other words, search for all files/directories in [directory] or it's subdirectories, excluding the [path to ignore], that match the [pattern].

find [directory] -path "[path to ignore]" -prune -o -print | grep "[pattern]"

Last modified: 07/05/2006 (most likely earlier as a site migration in 2006 reset some dates) Tags: (none)

Go to top

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top