From owner-freebsd-questions@FreeBSD.ORG Tue Feb 17 07:12:44 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 6ECD216A4CE for ; Tue, 17 Feb 2004 07:12:44 -0800 (PST) Received: from tomts36-srv.bellnexxia.net (tomts36-srv.bellnexxia.net [209.226.175.93]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2238B43D1F for ; Tue, 17 Feb 2004 07:12:44 -0800 (PST) (envelope-from dlavigne6@sympatico.ca) Received: from genisis ([64.230.83.103]) by tomts36-srv.bellnexxia.net (InterMail vM.5.01.06.05 201-253-122-130-105-20030824) with ESMTP id <20040217151243.QCAF1799.tomts36-srv.bellnexxia.net@genisis>; Tue, 17 Feb 2004 10:12:43 -0500 Date: Tue, 17 Feb 2004 10:16:18 -0500 (EST) From: Dru X-X-Sender: dlavigne6@genisis.domain.org To: Erik Trulsson In-Reply-To: <20040216223158.GA12956@falcon.midgard.homeip.net> Message-ID: <20040217100421.R629@genisis.domain.org> References: <20040216163818.R609@genisis.domain.org> <20040216223158.GA12956@falcon.midgard.homeip.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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: Tue, 17 Feb 2004 15:12:44 -0000 On Mon, 16 Feb 2004, Erik Trulsson wrote: > 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. Well, I played some more and piping to cpio did the trick. I couldn't do it in one go as pass mode doesn't support the interactively rename switch, but a temporary copy out followed by an interactive copy in worked. I then tried pax -rwi which was even more efficient as it let me rename while find was creating the list. Dru