Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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:

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

You must log in to answer this question.

Browse other questions tagged .