From owner-freebsd-questions@FreeBSD.ORG Mon Feb 16 14:32:01 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D863B16A4CE for ; Mon, 16 Feb 2004 14:32:01 -0800 (PST) Received: from falcon.midgard.homeip.net (h201n1fls24o1048.bredband.comhem.se [212.181.162.201]) by mx1.FreeBSD.org (Postfix) with SMTP id C423943D2D for ; Mon, 16 Feb 2004 14:32:00 -0800 (PST) (envelope-from ertr1013@student.uu.se) Received: (qmail 15251 invoked by uid 1001); 16 Feb 2004 22:31:58 -0000 Date: Mon, 16 Feb 2004 23:31:58 +0100 From: Erik Trulsson To: Dru Message-ID: <20040216223158.GA12956@falcon.midgard.homeip.net> Mail-Followup-To: Dru , questions@freebsd.org References: <20040216163818.R609@genisis.domain.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040216163818.R609@genisis.domain.org> User-Agent: Mutt/1.5.6i cc: questions@freebsd.org Subject: Re: copying files with same name X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Feb 2004 22:32:02 -0000 On Mon, Feb 16, 2004 at 04:49:37PM -0500, Dru wrote: > > Okay, I must be missing something obvious here. How do you do a batch copy > while renaming the destination files? I want to copy all of the configure > scripts in /usr/ports to ~/scripts. I can get find to find the files, I > can get sed to rename them, but I can't get the timing down right. > > cp -v `find /usr/ports -name configure -print | sed 's:/:=:g'` . > > renames the files nicely (so they're not all named configure), but does it > too soon--the source no longer exists. > > cp -v `find /usr/ports -name configure -print -exec sed 's:/:=:g' {} \;` . > > gives a syntax error (missing }) and > > cp -v `find /usr/ports -name configure -print | sed 's:/:=:g'` . > > has sed complain of extra characters at the end of a p command, followed > by all my destination files being named configure. > > Is there a way to do this as a one-liner, or does one have to write a > shell script with a while loop? First you should note that there are two ways of using cp(1). The first one is of teh form 'cp src-file dst-file' and the second one is of the form 'cp src-file1 src-file2 src-file3 ... dstdir' So if you don't want the dest-file to have the same name as the source, you must invoke cp(1) once for each file. You will have to use some kind of loop to do this. A for loop iterating over the output of find(1) would seem to be better suited for this problem than a while loop. -- Erik Trulsson ertr1013@student.uu.se