Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'?

share|improve this question
3  
no, you're wrong, cp -r does not delete files, only adds. You're copying them somewhere else. –  sivann Nov 8 '12 at 15:50
    
You're right. My mistake. Thank you! –  Bruce Nov 8 '12 at 15:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.