[comp.unix.questions] Sys V does not have a recursive copy cmd...

mitchell@cadovax.UUCP (Mitchell Lerner) (12/20/86)

Hey,  I just noticed that System V does not have a cp that does recursive
copies.  What are some of the ways that I could do this?  Is there a 
shell script that someone has that does this?	

						Thanx.

jmc@ptsfa.UUCP (Jerry Carlin) (12/20/86)

In article <1269@cadovax.UUCP> mitchell@cadovax.UUCP (Mitchell Lerner) writes:
>
>... System V does not have a cp that does recursive copies...

Try "find . -print|cpio -pduvm /foo/bar/...".

You can do a LOT with "find -print|foobar" and "find -print|xargs" types
of commands.

-- 
voice= 415 823-2441
uucp={ihnp4,dual,qantel}!ptsfa!jmc

sven-e@obelix.UUCP (Sven L Eriksson) (01/04/87)

In article <1964@ptsfa.UUCP> jmc@ptsfa.UUCP (Jerry Carlin) writes:
>In article <1269@cadovax.UUCP> mitchell@cadovax.UUCP (Mitchell Lerner) writes:
>>
>>... System V does not have a cp that does recursive copies...
>
>Try "find . -print|cpio -pduvm /foo/bar/...".
>
Another way to do this copy is to use tar. (Tape file ARchiver)

	tar cf - . | (cd todir ; tar xf - )

If you use this command links between files in the tree will be kept.
Otherwise it will work exactly as the find|cpio version.

Wich version is fastest? 

-- 

	Sven L Eriksson
	University of Linkoping
	Sweden

UUCP:	{decvax!mcvax,seismo}!enea!liuida!obelix!sven-e
ARPA:	sven-e@obelix.ida.liu.se

wcs@ho95e.UUCP (01/07/87)

In article <487@obelix.UUCP> sven-e@obelix.UUCP (Sven L Eriksson) writes:
>In article <1964@ptsfa.UUCP> jmc@ptsfa.UUCP (Jerry Carlin) writes:
>>In article <1269@cadovax.UUCP> mitchell@cadovax.UUCP (Mitchell Lerner) writes:
>>>... System V does not have a cp that does recursive copies...
>>Try "find . -print|cpio -pduvm /foo/bar/...".
>Another way to do this copy is to use tar. (Tape file ARchiver)
>	tar cf - . | (cd todir ; tar xf - )
>If you use this command links between files in the tree will be kept.

With either method, make sure your ulimit is large enough for any files
that you may be copying.  I've been burned by copying a multi-megabyte
database with a 1MB ulimit.  (Yes, I think ulimit is brain-damaged too.)
-- 
# Bill Stewart, AT&T Bell Labs 2G-202, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs

meissner@dg_rtp.UUCP (Michael Meissner) (01/07/87)

In article <487@obelix.UUCP> sven-e@obelix.UUCP (Sven L Eriksson) writes:
>In article <1964@ptsfa.UUCP> jmc@ptsfa.UUCP (Jerry Carlin) writes:
>>In article <1269@cadovax.UUCP> mitchell@cadovax.UUCP (Mitchell Lerner) writes:
>>>
>>>... System V does not have a cp that does recursive copies...
>>
>>Try "find . -print|cpio -pduvm /foo/bar/...".
>>
>Another way to do this copy is to use tar. (Tape file ARchiver)
>
>	tar cf - . | (cd todir ; tar xf - )
>
>If you use this command links between files in the tree will be kept.
>Otherwise it will work exactly as the find|cpio version.

Some nits:

    1)	find ... | cpio -p...  does preserve links as well;

    2)	If you are copying with find|cpio, use the -depth switch (so the
	files within a directory are copied before changing the directory
	permissions (useful if you are copying a directory subtree where
	the directory is set read-only).  The command would then look like:

		find . -depth -print | cpio -pduvm /foo/bar/...

    3)	If you are copying to same file system, you can add the 'l' option
	to the cpio, and it will try to link the copied file to the original
	before doing a copy (saves on disk space).  The command would be:

		find . -depth -print | cpio -plduvm /foo/bar/...

    4)	Some early 3B system V.0 did not supply tar.

    5)	If the files are large, I would imaging the find|cpio solution would
	be much faster than the two tar's (the data in the file is only
	copied once, plus the pathnames which are read/written to the pipe
	compared to the first tar writing everything into a pipe, and the
	second tar reading the pipe and writing it to the disk).

    6)	Find|cpio is more general, because you can selectively copy portions
	of the subtree, instead of the whole thing.  For example, if I wanted
	to copy a subtree, except for the emacs (CCA based) backup files, I
	would do:

		find . -depth ! -name "*~" -print | cpio -plvudm /foo/bar
-- 
	Michael Meissner, Data General
	...mcnc!rti-sel!dg_rtp!meissner

james@bigtex.uucp (James Van Artsdalen) (01/09/87)

IN article <487@obelix.UUCP>, sven-e@obelix.UUCP (Sven L Eriksson) wrote:
> In article <1964@ptsfa.UUCP> jmc@ptsfa.UUCP (Jerry Carlin) writes:
> >Try "find . -print|cpio -pduvm /foo/bar/...".

> Another way to do this copy is to use tar. (Tape file ARchiver)

> 	tar cf - . | (cd todir ; tar xf - )

> If you use this command links between files in the tree will be kept.
> Otherwise it will work exactly as the find|cpio version.

I believe cpio will always maintain links between trees.  If the "-l" option
is given to the "cpio -p..." above, then cpio will link the new files if
possible, making it analogous to a tree oriented ln.  In this last case
cpio is certainly faster than tar iff the source and destinations are on
the same file system.  Even if cpio cannot simply link the new files to the
old ones I would except cpio to be quite a bit faster, because the cpio
moves much less data through the pipe than the tar method does, and running
one copy of cpio -p presumably has less overhead than two copies of tar.
-- 
James R. Van Artsdalen   ...!ut-sally!utastro!bigtex!james   "Live Free or Die"
Voice: (512)-323-2675  Modem: (512)-323-2773  5300B McCandless, Austin TX 78756