Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!stc!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.unix.questions Subject: Re: Way to get find to skip a directory? Message-ID: <1882@root44.co.uk> Date: 11 Apr 90 12:35:48 GMT References: <133@dynasys.UUCP> <586@atcmpe.atcmp.nl> Reply-To: gwc@root.co.uk (Geoff Clare) Organization: UniSoft Ltd, London, England Lines: 37 jessea@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@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@root.co.uk (Dumb mailers: ...!uunet!root.co.uk!gwc) Tel: +44-1-315-6600 (from 6th May 1990): +44-71-315-6600