From owner-freebsd-hackers@FreeBSD.ORG Sat Jul 17 18:33:54 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D260716A4CE; Sat, 17 Jul 2004 18:33:54 +0000 (GMT) Received: from fillmore.dyndns.org (port-212-202-50-15.dynamic.qsc.de [212.202.50.15]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8819043D54; Sat, 17 Jul 2004 18:33:54 +0000 (GMT) (envelope-from eikemeier@fillmore-labs.com) Received: from dhcp-5.local ([172.16.0.5] helo=dhcp-11.local) by fillmore.dyndns.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.40 (FreeBSD)) id 1Blu0M-000207-Oz; Sat, 17 Jul 2004 20:33:53 +0200 Date: Sat, 17 Jul 2004 20:34:44 +0200 Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v482) To: Peter Pentchev From: Oliver Eikemeier In-Reply-To: <20040716152418.GB1589@straylight.m.ringlet.net> Message-Id: Content-Transfer-Encoding: 7bit User-Agent: KMail/1.5.9 cc: hackers@freebsd.org cc: Alfred Perlstein Subject: Re: RFC: "-exit" option for find(1) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jul 2004 18:33:55 -0000 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