PRUNING DIRECTORIES WITH FIND
                            By Borax Man

                            31 July 2025

This post explains when using the command line utility 'find', how to
use the '-prune' option, to exclude particular files or directories
from finds search results.

This is a response to a question on a forum asked a long time ago.  As
I sometimes forget myself, how to properly use the '-prune' option of
'find', I thought I'd leave this note here.

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, i.e. "." 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, i.e. "-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.

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

i.e.,


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