leo@atcmp.nl (Leo Willems) (04/08/90)
From article <133@dynasys.UUCP>, by jessea@dynasys.UUCP (Jesse W. Asher): > 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. > Try: cd /usr find `ls | grep -v spool` -print | some_prog This implies that your version of find(1) must be able to accept more than one starting point in a tree. Not all find versions do. In that case try this: ( cd /usr for i in `ls | grep -v spool` do find $i -print done ) | some_prog Leo Willems Internet: leo@atcmp.nl AT Computing UUCP: mcvax!hp4nl!kunivv1!atcmpe!leo P. O. Box 1428 6501 BK Nijmegen Phone: +31-80-566880 The Netherlands Fax: +31-80-555887
gwc@root.co.uk (Geoff Clare) (04/11/90)
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