[lug] Displaying a list of files

Tkil tkil at scrye.com
Thu Dec 12 13:13:57 MST 2002


>>>>> "Jeff" == Jeff Schroeder <jeff at neobox.net> writes:

Jeff> Can xargs handle an enormous list of files?  

Yes.  It will shove as many args onto one line as it can, fire off
that process, then start accumulating again.

Jeff> If I run 'find' against a deep directory tree, I might come up
Jeff> with thousands of files (worst case).  That tends to break some
Jeff> commands because the shell has a limited number of characters
Jeff> (2k?) it can process.  

There's another limitation that sometimes comes into play; some OSs
can only handle so many arguments to the 'exec' system call, which
puts another limit on this.

Jeff> Thus, I can't do things like:

Jeff>    grep -li "stuff" `find -type f`

Jeff> because the 'find' results are too massive.

Yes, xargs will handle this just fine:

| $ seq -w 1 10000 | xargs perl -lwe 'print "pid $$, ", scalar(@ARGV), " args"'
| pid 13386, 1024 args
| pid 13387, 1024 args
| pid 13388, 1024 args
| pid 13389, 1024 args
| pid 13390, 1024 args
| pid 13391, 1024 args
| pid 13392, 1024 args
| pid 13393, 1024 args
| pid 13394, 1024 args
| pid 13395, 784 args

So, for 10000 "arguments", xargs only launches 10 processes.

t.



More information about the LUG mailing list