copying files with same name

Dru dlavigne6 at
Tue Feb 17 07:12:44 PST 2004

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.


More information about the freebsd-questions mailing list