fvosberg
fvosberg

Reputation: 697

How to sync files in directory a from directory b?

I have two folders:

Directory A:

- test.txt
- subfolder1/test2.txt

Directory B:

- test.txt
- test4.txt
- subfolder1/test2.txt
- subfolder1/test3.txt

Now, I want to sync the files in directory A from B, but only the files, which exist in A. So, when I change test4.txt, nothing should happen, but when I change subfolder1/test2.txt, it should be synced.

My approach is following. Get a list of the files in directory A with relative path to directory a. Supply it as an argument to rsync relative to directory B and sync to A. Is it right? So I need a bash script? I am not very experienced in bash scripting.

How can I get the relative paths? Have I cd into the directory and execute find *?

Thanks a lot

Upvotes: 1

Views: 350

Answers (1)

vbo
vbo

Reputation: 13593

Rsync has an option to only update files without creating new ones. From man:

--existing              skip creating new files on receiver

Example rsync command for your case:

$ rsync -r --existing B/ A/

Upvotes: 2

Related Questions