问题
I am trying to sync two folders
/developer
and /shared
( in ubuntu )
when I modify a file in /shared
, I would like to be able to copy the file to the /developer
folder
I tried
rsync -r /shared /developer
But it seems to copy everything, although I changed only two files there.
How to copy only the changed files.
I also tried
rsync -rtu /shared /developer
somehow I can't get my head around this.
Please help.
回答1:
Try this:
rsync -a /shared/ /developer/
The first time you run that it will update the access times etc. for every file, but subsequent runs will only copy what's updated.
-a
means "archive". It implies-r
, but also-t
which is what you're missing.- The trailing slashes on the directory names are important. With no slash it'll copy the source directory into the destination directory, like
cp
does. This means it behaves differently when the destination already does or does not exist.
Edit: if you expect it to remove files that no longer exist in /shared
then add --delete
, and use it carefully.
来源:https://stackoverflow.com/questions/50842443/using-rsync-to-sync-only-files-that-are-modified