copying directories
Greg Galperin
grg22 at ai.mit.edu
Sun Jan 20 12:39:39 EST 2002
John Chambers wrote:
>
> | cp -r -p <src> <dest> to copy recursively and preserves file
> | attributes.
>
> One thing missing from this is that novices are usually rather
> surprised and disappointed that, if <src> is a directory, this
> doesn't make <dest> a copy of <src>. Rather, it creates a
> subdirectory of <dest> named the same as <src> and puts the files
> there. This is almost always not what was expected. There has never
> been a simple way to get the unix cp command to simply copy one
> directory to another.
...
> The cleanest way to make <dest> into a copy of <src> is with a tar or
> cpio command. For example:
>
> tar cf - <src> | (cd <dest>; tar xpf -)
> or
> find <src> -print | cpio -pdum <dst>
Actually, I like to use the "rsync" command to do this; it solves the
problem as such (from the rsync man page):
rsync -avz foo:src/bar /data/tmp
this would recursively transfer all files from the direc-
tory src/bar on the machine foo into the /data/tmp/bar
directory on the local machine. The files are transferred
...
rsync -avz foo:src/bar/ /data/tmp
a trailing slash on the source changes this behavior to
transfer all files from the directory src/bar on the
machine foo into the /data/tmp/. A trailing / on a source
name means "copy the contents of this directory". Without
a trailing slash it means "copy the directory". This dif-
Note that you can use rsync to transfer files on the same host also; just
don't specify any other hosts. So to copy the contents of src into dst:
rsync -av src/ dst
--grg
More information about the Discuss
mailing list