|
|
Subscribe / Log in / New account

So, is there a reason not to make the arg. list length grow dynamicly?

So, is there a reason not to make the arg. list length grow dynamicly?

Posted Aug 30, 2007 15:24 UTC (Thu) by welinder (guest, #4699)
In reply to: So, is there a reason not to make the arg. list length grow dynamicly? by liljencrantz
Parent article: The vi editor causes brain damage

xargs has very nice applications not related to very long command
lines. For example, it enables the "find" and "do" stages to work
in parallel:

find . -type f -print | xargs -n100 grep oink /dev/null

(Bonus points for knowing why that /dev/null is there and points
for fixing the space problems using the 0 flags.)


to post comments

So, is there a reason not to make the arg. list length grow dynamicly?

Posted Aug 30, 2007 16:53 UTC (Thu) by stuart_hc (guest, #9737) [Link] (1 responses)

The /dev/null argument is there so standard grep will see at least two file arguments and therefore always output the filename of matches. GNU grep adds the extension -H or --with-filename making this trick unnecessary.

So, is there a reason not to make the arg. list length grow dynamicly?

Posted Aug 30, 2007 21:28 UTC (Thu) by dfsmith (guest, #20302) [Link]

I suspect it's more to do with not hanging on stdin when find doesn't find anything.

So, is there a reason not to make the arg. list length grow dynamicly?

Posted Aug 30, 2007 17:54 UTC (Thu) by zlynx (guest, #2285) [Link]

Speaking of parallel operations, use find with -n and -P for more fun. Really great on SMP systems.

IO is usually the limit, but some operations take more time, like a complicated perl -i transform over a whole Linux kernel tree, for example. Or xsltproc.

You can also get to a CPU limit instead of a disk limit these days by using compressed data, either gzipped on disk, or something like Reiser4 with file compression.

Speaking of which, I find most high end workstations quite disappointing these days. Designers need to spend more time adding fast disk.

print0 is an evil kludge

Posted Aug 31, 2007 14:35 UTC (Fri) by emj (guest, #14307) [Link]

find . -type f -print0 |xargs -r -0 -n100 grep oink

Note the -r

I wish there was a better way to do -print0, I mean you can't do a ls -0|xargs -0 ls to skip problems with spaces right?


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds