2

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.

3

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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