copying directories
John Chambers
jc at trillian.mit.edu
Sun Jan 20 11:33:10 EST 2002
| 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.
For example, if you try "cp -rp foo bar" and bar is already a bar
directory, you find that there's now a bar/foo directory, and it
contains copies of the files in foo. That's not what you wanted, so
you try "cp -rp foo/* bar", and find that it almost works, but none
of the hidden files are copied. So next you try to get those copied
by "cp -rp foo/* foo/.* bar", and what this does is copies all of
foo/.. into bar. Oops...
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>
(This was taken from a BSD man pages. For some reason, the linux man
pages for tar and cpio give no examples. Neither do the "info" docs.
I'm not really impressed here. This is really not excusable for such
complex commands. ;-)
--
What if the Hoky Poky really IS what it's all about?
More information about the Discuss
mailing list