res@cbnews.ATT.COM (Robert E. Stampfli) (01/06/90)
Is there anyway to execute a "find" command while explicitly excluding the search of certain branches? For instance, suppose I want to visit each file in an entire Unix system except for those in /u or /usr/src. I have not found any combination of "! -name /u -a ! -name /usr/src" that worked. Of course, I could pipe the results thru grep, but that would be an expensive waste of time if /u and /usr/src contained many files and directories. Anyone have a solution? -- Rob Stampfli / att.com!stampfli (uucp@work) / kd8wk@w8cqk (packet radio) 614-864-9377 / osu-cis.cis.ohio-state.edu!kd8wk!res (uucp@home)
tale@cs.rpi.edu (David C Lawrence) (01/06/90)
In <12847@cbnews.ATT.COM> res@cbnews.ATT.COM (Robert E. Stampfli) and in <104@melpar.UUCP> toppin@melpar.UUCP (Doug Toppin) both ask essentially the same question about the find command. The manual page provides the solution, but find is admittedly a rather cumbersome programme to work with at times because of its curious array of arguments. The solution lies in the -prune option; both Robert's and Doug's cases would use it in the same way: find DIR -name EXCLUDEDIR -prune -o WHATEVER DIR would be the directory to start the search in, as usual. EXCLUDEDIR is the name of the local component (basname) of the directory -- unfortunately something like "src/test" to just exclude test directories under source directories won't work. WHATEVER would be the normal arguments for whatever you are doing, "-type f -ls" or "-name '*.c' -print" or "WHATEVER" :-). This should probably be added to Frequently Asked Questions which makes reference to find(1) being a powerful command and encourages learning it, but a lot of people just can't learn from the manual page. A pointer to one or two better sources of information about it would be good. Dave -- (setq mail '("tale@cs.rpi.edu" "tale@ai.mit.edu" "tale@rpitsmts.bitnet"))
dalgic@Neon.Stanford.EDU (Ismail Dalgic) (01/06/90)
In article <F`K$B-@rpi.edu> tale@cs.rpi.edu (David C Lawrence) writes: > >The solution lies in the -prune option; both Robert's and Doug's cases >would use it in the same way: > >find DIR -name EXCLUDEDIR -prune -o WHATEVER Hmm. I also had the same question in my mind. However, the problem is that there is no -prune option nor anything similar in Ultrix `find'. So, does anybody have a solution for Ultrix systems? --Ismail DALGIC
cpcahil@virtech.uucp (Conor P. Cahill) (01/06/90)
In article <F`K$B-@rpi.edu>, tale@cs.rpi.edu (David C Lawrence) writes: > essentially the same question about the find command. The manual > page provides the solution, but find is admittedly a rather cumbersome > programme to work with at times because of its curious array of arguments. > > The solution lies in the -prune option; both Robert's and Doug's cases > would use it in the same way: > > find DIR -name EXCLUDEDIR -prune -o WHATEVER The only problem with this is that the "-prune" option is not an option on most versions of find. Stock System V and Stock 4.3BSD do not include it as an option. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+
guy@auspex.auspex.com (Guy Harris) (01/07/90)
>The solution lies in the -prune option; both Robert's and Doug's cases >would use it in the same way: Not necessarily. "-prune" is a Sunism; although it's in the version of "find" distributed with the NFS source code, and will, I think, be in System V Release 4 (it's in SVID Issue 3, so it had *better* be in S5R4!), it's not in every version of "find" out there. I suspect the version of "find" that came with the Xenix that one of the people in question had included "-prune"; I don't know what version of UNIX the other person had, but it might or might not have "-prune". On top of that, >find DIR -name EXCLUDEDIR -prune -o WHATEVER would stop the search at *any* directory named EXCLUDEDIR, which is a *component* name, not a *path* name; this would permit you to prevent "find" from searching *any* directory named "test", but wouldn't permit you to prevent "find" from searching "/u" and "/usr/src" unless you knew that no other directories that you wanted to search were named "u" or "src". To fix the latter problem, I'd be tempted to try enumerating all directories under "/" other than "/u" and "/usr", and all directories under "/usr" other than "/usr/src", and hand that list of directories to "find" as the set of directories it should search (all versions of "find" with which I'm familiar take a *list* of directories to search, not just a single directory).
gwyn@smoke.BRL.MIL (Doug Gwyn) (01/07/90)
In article <12847@cbnews.ATT.COM> res@cbnews.ATT.COM (Robert E. Stampfli,55216,cb,1C315,6148604268) writes: >not found any combination of "! -name /u -a ! -name /usr/src" that worked. You need to use PATTERNS for the names, not just PREFIXES.