使用 rsync 只同步被修改的文件 [英] Using rsync to sync only files that are modified

查看:18
本文介绍了使用 rsync 只同步被修改的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试同步两个文件夹

I am trying to sync two folders

/developer/shared(在 ubuntu 中)

/developer and /shared ( in ubuntu )

当我修改 /shared 中的文件时,我希望能够将文件复制到 /developer 文件夹

when I modify a file in /shared , I would like to be able to copy the file to the /developer folder

我试过了

rsync -r /shared /developer

但它似乎复制了所有内容,尽管我只更改了那里的两个文件.

But it seems to copy everything, although I changed only two files there.

如何仅复制更改的文件.

How to copy only the changed files.

我也试过

rsync -rtu /shared /developer

不知怎么的,我无法理解这个.

somehow I can't get my head around 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 表示存档".它意味着 -r,但也包含 -t,这正是您所缺少的.
  • 目录名称的尾部斜杠很重要.没有斜线,它会将源目录复制到目标目录,就像 cp 一样.这意味着当目的地已经存在或不存在时,它的行为会有所不同.
  • -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.

如果您希望它删除 /shared 中不再存在的文件,则添加 --delete,并小心使用.

if you expect it to remove files that no longer exist in /shared then add --delete, and use it carefully.

这篇关于使用 rsync 只同步被修改的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆