Way to get find to skip a directory?

Geoff Clare gwc at root.co.uk
Wed Apr 11 22:35:48 AEST 1990


jessea at dynasys.UUCP (Jesse W. Asher) writes:
> Is there a way to get find to skip a directory when searching?  An example
> would be that I want to search /usr for something but I know it's not going
> to be in /usr/spool/news.  Is there any way I can get it to search /usr
> but skip /usr/spool/news (which can take forever to scan)?  Thanx in advance.

leo at atcmp.nl (Leo  Willems) writes:
>Try:
>
>cd /usr
>find `ls | grep -v spool` -print | some_prog

Good try, but that will miss out any files in /usr beginning with "." or
which contain "spool" in their name (e.g. /usr/spooler).  It also doesn't
quite answer the original question, which was to skip just /usr/spool/news,
not the whole of /usr/spool.

To do it properly you need to change the `ls |grep -v spool` to:

`ls -ad * .* spool/* spool/.* | egrep -v '^(\.*|spool|spool/\.*|spool/news)$'`

Pretty vile, isn't it?

On the other hand, if you're lucky, you may have one of the newer versions
of "find" which recognizes "-prune" and "-path".  In that case you can do:

find /usr \( -path /usr/spool/news -prune \) -o -print

I know HP-UX has these, but I'm not sure about any other systems.

Note that using "-prune" with "-name" (if you don't have "-path") would
miss out ALL directories called "news", not just /usr/spool/news.  This
is an all-too-common pitfall.
-- 
Geoff Clare, UniSoft Limited, Saunderson House, Hayne Street, London EC1A 9HH
gwc at root.co.uk  (Dumb mailers: ...!uunet!root.co.uk!gwc)  Tel: +44-1-315-6600
                                         (from 6th May 1990): +44-71-315-6600



More information about the Comp.unix.questions mailing list