Copying a dirctory subtree (Was: Why no job control in 386/ix?)

Ted Powell ted at eslvcr.UUCP
Thu Nov 30 06:21:37 AEST 1989


In article <483 at mwtech.UUCP> martin at mwtech.UUCP (Martin Weitzel) writes:
>In article <15246 at haddock.ima.isc.com> suitti at anchovy.UUCP (Stephen Uitti) writes:
> ...
>>	% find . -print | cpio -ocB | (cd otherdir ; cpio -icdmB)
>>seems to work.  I know, cpio has an option to just copy the directory
>>tree without the other invocation of cpio, but cpio has lots of options...
> ...
>BTW: If memory serves, try cpio -p ...
> ...
See the last example on the (AT&T) cpio man page. I added the -a option
to the ones shown there because I wanted to preserve as many attributes 
as possible. If one executes this pipeline as root, just about everything
remains intact: ownerships, permissions, multiple links to the same
file, date stamps. I got into this because I wanted to move /usr/spool
to its own (128mb) file system, with many megabytes and lots of multiple
links already in /usr/spool/news. Note that when the destination _is_ in
the same filesystem, things go really fast, because (thanks to the -l
option) only directory entries are manipulated, and not the actual file
content. With the cpio -o | cpio -i quoted above, you are necessarily
moving all the data.
    For ease of use, I have the following alias:
	alias treeto 'find . -depth -print | cpio -padlmv'  # .cshrc
	alias treeto='find . -depth -print | cpio -padlmv'  # .kshrc
To copy the directory subtree under /foo/bar to the directory /baz/quux:
	su		# if the files aren't all yours
	cd /foo/bar
	treeto /baz/quux
-- 
ted at eslvcr.wimsey.bc.ca   ...!ubc-cs!van-bc!eslvcr!ted    (Ted Powell)



More information about the Comp.unix.i386 mailing list