2

How can I copy files from source to destination, where in all the files existing in destination (with directory structure), only should be copied from the source, overwritten in the destination. Rest of the files (including the directory structure) should not be copied from source to destination. I think rsync can achieve this, not sure on the options we have to select.

  • You only want to copy files --existing on the target? Hm, should be possible . . . – Dubu Jul 26 '13 at 12:43
2

Thanks @Dubu I didn't know that flag existed. Here's an example:

$ ls -R src ; ls -R dst
src:
a  b  c  empty_dir  sub_dir

src/empty_dir:

src/sub_dir:
e  f
dst:
a  c  sub_dir

dst/sub_dir:
f
$ rsync --recursive --existing --verbose src/ dst
sending incremental file list
a
c
sub_dir/f

sent 262 bytes  received 71 bytes  666.00 bytes/sec
-1

Go for "rsync" Use it as, "rsync source destination" it's same as you use command "cp".

  • Can you provide a working example? – Braiam Jul 26 '13 at 13:07

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.