Sheldon Hearn <[EMAIL PROTECTED]> wrote:
 > On Sat, 21 Apr 2001 14:06:04 +0100, Brian Somers wrote:
 > > How do you do this in a script:
 > > 
 > >   cd /topdir; find . -type f | xargs -i {} cp {} /otherdir/.
 > for i in `find /path/to/source -type f`; do
 >         cp $i /path/to/dest/
 > done

That can overflow your shell's command line limit (at the
"for" command).  True, our /bin/sh doesn't has such a
limit, AFAIK, but there _are_ shells that do).  Apart from
that it is extremely inefficient, because it runs a "cp"
for every single file.  These are exactly the problems that
xargs is supposed to solve.

Actually I don't see any problem with Brian's approach
(provided that the -i option exists, of course).
xargs _does_ take the size of the environment into account,
as well as the size of all arguments, and it still leaves
much room (it only uses up to ARG_MAX - 2048 by default).

Oh by the way, in this particular example it is probably a
good idea to use cpio.  This will even work with our xargs
(which doesn't support -i yet):

   cd /topdir; find . -type f | cpio -dup /otherdir

should do exactly that job.


Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"All that we see or seem is just a dream within a dream" (E. A. Poe)

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to