[PLUG] Re: Unix Tip: TOO MANY FILES AROUND

Rogan Creswick creswick at gmail.com
Wed Oct 11 22:08:40 UTC 2006


On 10/11/06, Auke Kok <sofar at foo-projects.org> wrote:
> Roderick A. Anderson wrote:
>  > Well you can do the following:
>  >
>  > $ls |xargs grep "ABC"
>
> That's rather funny - effectively it should do the same, except that xargs doesn't call
> the shell to pass the arguments. Apparently on that platform `ksh` is limiting the
> amount of arguments more than the platform itself, and I would definately consider that
> a ksh bug :)

As I understand it, using the pipe turns the list of command line args
into a fifo pipe from ls to xargs -- the pipe can then be any size (as
long as it can hold one file name).  xargs is then responsible for
managing storage of the entries, and (probably) processes them as they
come in.  It does the same thing, but in a very different way -- it
allows lazy evaluation of the arg list, in effect.

One should note that the above command will fail without passing "-0"
to xargs -- it will break on files / directories with spaces
otherwise.

ls | xargs -0 grep "ABC"

--Rogan

>
> It also exposes that ksh uses /usr/bin/find internally in a rather stupid way :)
>
> Anyway, if you're really doing something like above, you should have used:
>
> grep -r "ABC" .
>
> which doesn't care how many files there are :)
>
>
> Cheers,
>
> Auke
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>



More information about the PLUG mailing list