Grep Guru

Giorgos Keramidas keramida at ceid.upatras.gr
Mon Jun 9 19:08:19 UTC 2008


On Tue, 10 Jun 2008 01:44:36 +1000 (EST), Ian Smith <smithi at nimnet.asn.au> wrote:
>On Sun, 8 Jun 2008 16:07:12 -0700 Bill Campbell <freebsd at celestial.com> 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 <grepoptions> <text to search>
>>>
>>> There's no more need for find | xargs
>>>
>>> Try:
>>>
>>> find . -type -f -exec grep <grepoptions> <text to search> {} \+
>>>
>>> -exec foo {} \+ behaves like xargs foo
>>> -exec foo {} \; exec foo for every file
>
> Thanks for this kick; I'd missed or misunderstood using {} \+
>
>> The issue here is that grep execs grep for each file found while
>> xargs batches the files.
>
> If find(1) is to be believed, so does -exec utility [argument ...] {} +

Yes, sure.  I think Bill was just being extra-conservative[1] and he
explicitly chose to quote `+' with a backslash to avoid spurious
interpreration by the shell.  I also type `\+' out of habbit most
of the time.

[1] BSD users tend to be this way, but that's a good thing, right? :)



More information about the freebsd-questions mailing list