[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: How to overwrite the destination directory by 'cp'?
From: |
Voelker, Bernhard |
Subject: |
RE: How to overwrite the destination directory by 'cp'? |
Date: |
Fri, 22 Jan 2010 09:43:47 +0100 |
Peng Yu wrote:
> Suppose I have directory a and b, the following command will copy the
> content of a to b/a, rather than overwrite the directory 'b' by the
> directory 'a'. I'm wondering if there is an option to overwrite 'b'?
>
> cp -r a b
you mean something like this?
cp -r a/. b
Have a look with cp's option -v to see what it does:
$ mkdir a a/d1 a/d2 b b/d1 b/d3
$ touch a/f1 a/d1/d1f1 a/d1/d1f2 a/d2/d2f1
$ touch b/f1 b/f2 b/d1/d1f1 b/d1/d1f2 b/d3/d3f1
$ cp -rv a/. b
`a/./d1/d1f1' -> `b/./d1/d1f1'
`a/./d1/d1f2' -> `b/./d1/d1f2'
`a/./d2' -> `b/./d2'
`a/./d2/d2f1' -> `b/./d2/d2f1'
`a/./f1' -> `b/./f1'
$ find b | xargs ls -d1
b
b/d1
b/d1/d1f1
b/d1/d1f2
b/d2
b/d2/d2f1
b/d3
b/d3/d3f1
b/f1
b/f2
This is not 'overwriting' in the sense that the original
files and subdirectories of the destination are removed,
but actually it's more like 'merging a into b'.
Maybe that's what you want.
Have a nice day,
Berny