Using rsync to sync only files that are modified

痴心易碎 提交于 2019-12-24 10:55:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!