From owner-freebsd-current Sat Apr 21 7:51:31 2001 Delivered-To: freebsd-current@freebsd.org Received: from lurza.secnetix.de (lurza.secnetix.de [212.66.1.130]) by hub.freebsd.org (Postfix) with ESMTP id E6F3A37B43C for ; Sat, 21 Apr 2001 07:51:24 -0700 (PDT) (envelope-from olli@lurza.secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.9.3/8.9.3) id QAA04891; Sat, 21 Apr 2001 16:51:24 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Date: Sat, 21 Apr 2001 16:51:24 +0200 (CEST) Message-Id: <200104211451.QAA04891@lurza.secnetix.de> From: Oliver Fromme To: freebsd-current@FreeBSD.ORG Reply-To: freebsd-current@FreeBSD.ORG Subject: Re: cp -d dir patch for review (or 'xargs'?) In-Reply-To: <93802.987862964@axl.fw.uunet.co.za> X-Newsgroups: list.freebsd-current User-Agent: tin/1.5.4-20000523 ("1959") (UNIX) (FreeBSD/4.1-RELEASE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Sheldon Hearn 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