Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On linux, let's say I have some files like this:



and I want to copy them to a destination that already have dir1 and dir2 and looks like:





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



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

Your Answer


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

Browse other questions tagged or ask your own question.