Date: Sat, 17 Jul 2004 20:34:44 +0200 From: Oliver Eikemeier <eikemeier@fillmore-labs.com> To: Peter Pentchev <roam@ringlet.net> Cc: Alfred Perlstein <alfred@freebsd.org> Subject: Re: RFC: "-exit" option for find(1) Message-ID: <F950E6FE-D81F-11D8-BA2D-00039312D914@fillmore-labs.com> In-Reply-To: <20040716152418.GB1589@straylight.m.ringlet.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Peter Pentchev wrote: > On Fri, Jul 16, 2004 at 05:28:57PM +0300, Peter Pentchev wrote: >> On Fri, Jul 16, 2004 at 11:58:07AM +0400, Denis Antrushin wrote: >>> Alfred Perlstein wrote: >>>> I'm up too late, this doesn't work because find returns >>>> success whenever it successfully runs thought everything. >>>> >>>> Perhaps the primary change to just "-exit" which would >>>> make find exit successfully, and if the primary is never >>>> encountered (ie. our find logic never hits it) find would >>>> exit with a non-zero exit status? >>>> >>>> Ideas? Better ideas? >>>> >>>> The reason I want this is to avoid extracting a tarball >>>> over a directory that has files in it that are newer than >>>> the tarball. >>>> >>>> Neither tar nor find seem to make this easy... >>> What about this: >>> >>> test -n "`find . -type f -newer ../src.tar.gz`" && echo hi >> >> I believe Alfred's problem with this is that it will still traverse the >> whole hierarchy even after a match is found. In some cases, the >> hierarchy may be huge, and if the match is within the first 100-200 >> files, well... :) >> >> I wonder if it wouldn't be a bit better to add to find(1) something >> like >> -maxmatches N, similar to Alfred's idea, but not limited to a single >> match? > > Well, I've just gone ahead and implemented it: say hello to the new > -maxmatch N and -minmatch N primaries: > > -maxmatch n > Always true; exits after printing out n matching filenames. If > any -maxmatch primary is specified, it applies to the entire > expression even if it would not normally be evaluated. -maxmatch > 0 makes find exit immediately without performing any filesystem > traversal. > > -minmatch n > Always true; exits with a non-zero exit code if less than n > matching filenames were printed out at the end of the search. If > any -minmatch primary is specified, it applies to the entire > expression even if it would not normally be evaluated. > > Thus, -maxmatch 1 would help in Alfred's case. Patch attached. I don't really like this because: a) It's global b) It is counting printed lines, while I might want to use -exec or something else c) It does not honour find(1)s [+-]n semantic How about two primaries: - -exit n, like proposed in the first post (sucess could be determined by a printed line or an -exec) - -match n, which is true when *this* primary has been matched n times so find [path] ... -match 1 -print -exit 0 will do the trick, while find [path] ... -match -10 -print will print the first 9 matches? -Oliver
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F950E6FE-D81F-11D8-BA2D-00039312D914>