[svlug] Re: [svlug]how to copy a bunch of "." files?

Erik Steffl steffl at bigfoot.com
Sat May 6 13:32:31 PDT 2000

dfox at belvdere.vip.best.com wrote:
> > This is not correct.  The problem with find and its -exec flag is that
> > _FOR EACH PARAM GIVEN_ it will _FORK_ off a process to handle the -exec
> > request.
> I'd tend to agree with you here. The info pages on find(1) seem to
> support this -- and using the exec flag to grep through something
> like the linux source tree takes a lot longer than it does using
> xargs on my system.
> But based on what you said, I'd expect to see a forest of grep
> processes running, one per source file in the linux source tree, all
> looking for something (for the test, I looked in all source files for
> the word 'panic'). I did not notice anything forking new processes,
> despite repeated utterances of 'ps alx'. But it took substantially
> longer, with more think time at the start of the process than with
> an xargs solution.

  I did:

strace find . -name '*.txt' -exec grep rrr {} \; > & rrr
grep -A 1 'lstat.*txt' rrr

  the output reveals bunch of lines like this:

lstat("install.txt", {st_mode=S_IFREG|0644, st_size=4319, ...}) = 0
fork()                                  = 12790
lstat("copyright.txt", {st_mode=S_IFREG|0644, st_size=1618, ...}) = 0
fork()                                  = 12791
lstat("install.txt", {st_mode=S_IFREG|0644, st_size=4319, ...}) = 0
fork()                                  = 12792
lstat("copyright.txt", {st_mode=S_IFREG|0644, st_size=1618, ...}) = 0
fork()                                  = 12793
lstat("readme.txt", {st_mode=S_IFREG|0644, st_size=347, ...}) = 0
fork()                                  = 12794

> Furthermore, the xargs gives the data in a better presentation: the
> find -exec doesn't give the filenames, but the xargs does (using
> find . -name "*.[ch] | xargs grep 'panic' -).

  to clarify (you might have ment the same thing):

  it's not xargs who gives better representation, it's side effect, grep
does not print out the file name if it's processing just one file... but
in the end it's one huge advantage of xargs (when using find and grep


More information about the svlug mailing list