rsync by comparing destination directories

时间:2016-07-11 22:19:01

标签: bash shell unix rsync

I would like to copy updated files in one directory to the destination directory. The dest directory is not in the same fashion as the source directory.

Below is my source directory pattern and files:

/user/ks/src_dir

and the files

1.txt
2.txt
3.txt

Below is the dest directory structure and files :

/user/ks/dest_dir/1/1.txt
/user/ks/dest_dir/2/2.txt
/user/ks/dest_dir/3/3.txt

I would like to use rsync command to mirror and syncup any changes that come to any of the 3 files in the source directory w.r.t the corresponding files in the destination directories.So if we find an updation in 1.txt in the source dir then /user/ks/dest_dir/1/1.txt file has to be updated, if 2.txt in the source dir gets modified then /user/ks/dest_dir/2/2.txt file has to be updated and so on.

I have tried rsync options and in case of any source files getting updated it copies the modified files to the destination base directory only i.e. /user/ks/dest_dir/ which is not what i desire.

I am looking for any option which could help me in my use case. I could any other utility too other than rsync if that works.

1 个答案:

答案 0 :(得分:0)

您可以使用unison实用程序在两个方向同步:

unison -batch /user/ks/src_dir /user/ks/dest_dir