Date: Sat, 21 Apr 2001 16:51:24 +0200 (CEST) From: Oliver Fromme <olli@secnetix.de> To: freebsd-current@FreeBSD.ORG Subject: Re: cp -d dir patch for review (or 'xargs'?) Message-ID: <200104211451.QAA04891@lurza.secnetix.de> In-Reply-To: <93802.987862964@axl.fw.uunet.co.za>
next in thread | previous in thread | raw e-mail | index | archive | help
Sheldon Hearn <sheldonh@uunet.co.za> 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. Regards Oliver -- 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 majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200104211451.QAA04891>