Re: can I exclude a directory with find?



On Wed, 12 Jan 2011 20:04:53 -0800, Todd wrote:

On 01/12/2011 07:03 PM, Todd wrote:
Hi All,

I am not having any luck with the man page.

Using the "find" command, is there a way I can tell "find" not to look
in a particular directory?

Many thanks,
-T

Figured it out. Use the "!" and the "-path" switches:

find ! -path "*/abc/*" -iname \*.qbw

-T

For the sake of completeness, the '-prune' option works like this.

find (where to look) (what to prune) -o (what to find) -print

where to look = path to search, ie "." or "/home/john"

what to prune = statement regarding what we will remove, to remove a
directory, you use "-path './path_to_remove' -prune". This tells find
that any path matching ./path_to_remove will be pruned. The confusing
thing here, is we are using multiple command line options together as one
directive.

what to find = search term, ie "-iname 'file_to_find'".

so the end result would be something like

find . -path './path_to_remove' -prune -o -iname 'INSTALL' -print

I find a lot of the documentation confusing, because it simply gives you
the options, but doesn't show you the logical grouping.

In this example, we used " -path './my_path' -prune', but you don't have
to prune paths. You could use any of the other options, say -ctime 4 to
prune files created in the last 4 hours. So you could use "-ctime 4 -
prune" or "-executable -prune" to remove executables.

If you want to exclude multiple paths, then you add another "(what to
prune)" section as defined above after an additional -o

ie

find (where to look) (what to prune) -o (what to prune) -o (what to find)
-print

e.g.

find . -path './path_to_remove' -prune -o -path './other_path_to_remove' -
prune -o -iname 'INSTALL' -print
.