Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Hi how do I copy a folder from source to destination in Ubuntu without replacing the existing contents in the destination folder?

I tried cp -r -u and cp -r -n, and neither one worked.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

I believe that if you're copying a directory using -r, the -n will only take effect against the directory being copied, not individual files, leaving you with -i which is interactive though, which means you have to stick around to watch it go. Not useful if you're scripting I suppose.

What can work instead if you're copying a source which has multiple directories within, is rsync with the --ignore-existing flag. rsync can also work for local transfer, in fact, I prefer it for copying entire directory/subdir's..

share|improve this answer

It is cp -i for interactive queries before overwriting. You can find more with man cp.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.