Recursive Copy?

Mike Reinehr cmr
Sat Aug 12 11:45:55 PDT 2006


On Saturday 12 August 2006 03:06 am, Roger Oberholtzer wrote:
> On Sat, 2006-08-12 at 04:07 +0000, Steve Jardine wrote:
> > Okie all,
> >
> >     Here's the sceneraio:
> >
> >
> >     I have a directory tree:
> >
> > 	A-
> >
> > 	  |->B
> > 	  |->C
> >
> >           -->D-
> >                ->E
> >
> >
> >    In this directory tree I have possibly several same named files in
> > different directories. What I want to do is to recursively copy all the
> > files in the directory tree to a single directory, say directory F. In
> > that directory I would like duplicate files names to have prepended
> > differences.
> >
> >     Example:
> >
> >         A/B/t.txt
> >         A/C/t.txt
> >         A/D/E/t.txt
> >
> >     all being copied into the directory F looking like:
> >
> >        F/t1.txt
> >        F/t2.txt
> >        F/t3.txt
> >
> >     Any ideas?
> >
> >
> >     Thanks all for your responses - and further ideas...
>
> Perhaps something with cpio in pass-thru mode? There are options for
> making or not making directories.
>

I think I would use the 'find' command with a shell script to do the actual 
copying. For example:

	find A -type f -exec copy.sh {} ;

where copy.sh would be something like
(	NAME=`basename $1`
	if [ -f F/$NAME ]
	then	...	# keep a counter, add a suffix & then copy
	else		...	# just exec cp $1 F/$NAME
	fi
)

Be warned! This is just stream of conciousness stuff, here. I haven't tested 
anything. ;-)

Hope this helps!

cmr

-- 
Debian 'Sarge': Registered Linux User #241964

"More laws, less justice." -- Marcus Tullius Ciceroca, 42 BC



More information about the Linux-users mailing list