2
On linux, let's say I have some files like this:
dir1/file1
dir2/file2
and I want to copy them to a destination that already have dir1
and dir2
and looks like:
dir1/file1
dir1/file1a
dir2/file2
dir2/file2a
I want to only replace file1 and file2. But if I do cp -r
, dir1
in the destination gets replaced with the contents of dir1
from the source, as does dir2
, so I'm left with
dir1/file1
dir2/file2
in the destination. I lose files file1a
and file2a
!
How can I copy in a way that says 'copy any files you find to the corresponding directory if it exists, create a new directory only if necessary and do this recursively'?
4no, you're wrong, cp -r does not delete files, only adds. You're copying them somewhere else. – sivann – 2012-11-08T15:50:35.707