From owner-freebsd-questions@FreeBSD.ORG Mon Jun 9 14:25:12 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6BBC91065674 for ; Mon, 9 Jun 2008 14:25:12 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id D9FE08FC0C for ; Mon, 9 Jun 2008 14:25:11 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (adsl116-224.kln.forthnet.gr [77.49.235.224]) (authenticated bits=128) by igloo.linux.gr (8.14.3/8.14.3/Debian-4) with ESMTP id m59EOuaH024851 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 9 Jun 2008 17:25:03 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.2/8.14.2) with ESMTP id m59EOt5U063346 for ; Mon, 9 Jun 2008 17:24:55 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.2/8.14.2/Submit) id m59EOsvd063345; Mon, 9 Jun 2008 17:24:55 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: freebsd-questions@freebsd.org References: <484C3CC4.7050107@webrz.net> <20080608221328.U9955@wojtek.tensor.gdynia.pl> <20080608225023.GD54922@ma.sigsys.de> <20080608230712.GA24307@ayn.mi.celestial.com> Date: Mon, 09 Jun 2008 17:24:54 +0300 In-Reply-To: <20080608230712.GA24307@ayn.mi.celestial.com> (Bill Campbell's message of "Sun, 8 Jun 2008 16:07:12 -0700") Message-ID: <87od6an0sp.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: m59EOuaH024851 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.744, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.66, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Subject: Re: Grep Guru X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jun 2008 14:25:12 -0000 On Sun, 8 Jun 2008 16:07:12 -0700, Bill Campbell wrote: > On Mon, Jun 09, 2008, Raphael Becker wrote: >>On Sun, Jun 08, 2008 at 10:15:50PM +0200, Wojciech Puchar wrote: >>> find . -type f -print0|xargs -0 grep >> >>There's no more need for find | xargs >> >>Try: >> >>find . -type -f -exec grep {} \+ >> >>-exec foo {} \+ behaves like xargs foo >>-exec foo {} \; exec foo for every file > > The issue here is that grep execs grep for each file found while > xargs batches the files. The \+ trick behaves like xargs, so this shouldn't be an issue :) > This is of particular importance if one wants to see the file > names in the output. You can ensure the same even if xargs picks up a single file to grep with xargs -0 grep pattern /dev/null This will cost an open() / read() pair for each batch of files, but it ensures that grep will always see at least two file names, and it should print the filename of any matching files.