Skip to Content.
Sympa Menu

sm-discuss - Re: [SM-Discuss] Using xargs

sm-discuss AT lists.ibiblio.org

Subject: Public SourceMage Discussion List

List archive

Chronological Thread  
  • From: Karsten Behrmann <BearPerson AT gmx.net>
  • To: sm-discuss AT lists.ibiblio.org
  • Subject: Re: [SM-Discuss] Using xargs
  • Date: Fri, 16 Apr 2004 12:10:31 -0500

I agree that xargs is pretty nice when you're handling a giant bunch of files.
But I have not found many applications for that in sorcery yet.
grep 'regexp' $(find -type f)
would be my command of choice as long as it is only <50 files
> No, xargs is almost ALWAYS better. Read-on and you'll see why!
>
> Consider the common case of grepping all files in a tree. The solution most
> people use is:
>
> find . -type f -exec grep 'regexp' /dev/null "{}" ;
>
> but this is hideously inefficient. A separate grep is fork()'d and exec()'d
> for every single file. Eek!!! Note also the quotes around the {} to cope
> with
> files with spaces in them.
>
> By contrast:
>
> find . -type f -print0 | xargs -0 grep 'regexp'
>
> (a) looks easier on the eye
> (b) is WAAAAYY more efficient!
>
> A grep is forked/execed for every 32 worth of argument (and environment)
> space.
>
> If there's only one file found, then it's only marginally less efficient
> than
> the first example - you have the overhead of the xargs process.




Archive powered by MHonArc 2.6.24.

Top of Page