【问题标题】:Why this difference between "dir/" and "dir" with rsync [closed]为什么使用 rsync 的“dir/”和“dir”之间存在这种差异 [关闭]
【发布时间】:2016-03-07 13:44:29
【问题描述】:

我一直在努力解决一些我不理解的问题,我认为这是一个简单的rsync 命令行。

 rsync -u -v -r -n  "~/usb/.notes/_tech"  "~/.notes/_tech"

其中:usb 节点是(已知)usb 的挂载点。问题是以下两种变体给出了完全不同的结果。

示例 1

  $ rsync -u -v -r -n  "~/usb/.notes/_tech"  "~/.notes/_tech" | tee | wc -l
      :

  sent 94,378 bytes  received 6,340 bytes  201,436.00 bytes/sec
  total size is 13,222,770,177  speedup is 131,285.07 (DRY RUN)
  • 2,024 行(大约 ~ 2,020 个文件)

示例 2

  $ rsync -u -v -r -n  "~/usb/.notes/_tech/"  "~/.notes/_tech/" | tee | wc -l
      :

  sent 88,352 bytes  received 334 bytes  177,372.00 bytes/sec
  total size is 13,222,770,177  speedup is 149,096.48 (DRY RUN)
  • 23 行(大约 19 个文件)

Therefore ...我认为示例 #1 正在给我该树上的 All 文件。虽然,示例 #2 更符合我的预期(但这并不意味着它是“正确”)。

问题

  1. 为什么会有不同?!
  2. 哪种语法选择提供文件夹子树的这种简单的递归更新?
  3. 这种巨大差异背后的根本原因是什么?
    • 例如;在周末,我发现在考虑rsync 命令时我需要使用ls -lt**c**。 (一旦你意识到这一点就很明显了)。
    • 在谈到 rsync 时,“大小确实很重要”。
    • 我可以接受“dir/”与“dir”(无斜线)的语义差异。我看不出递归开关 (-r) 有什么不同。

我在示例中没有看到结构性问题;所以我正在从 stackoverflow 中寻求智慧?!洞察力?

寻求智慧。

【问题讨论】:

    标签: linux directory rsync


    【解决方案1】:

    您所有问题的答案都在手册页中:

    A trailing slash on the source changes this behavior to avoid
    creating an additional  directory level at the destination.
    You can think of a trailing / on a source as meaning "copy the
    contents of this directory" as  opposed to  "copy the directory
    by name", but in both cases the attributes of the containing
    directory are transferred to the containing directory on the
    destination.
    

    所以rsync -r /foo/ /tmp 会将/foo 中的所有内容放入/tmp,而rsync -r /foo /tmp 会将/foo 中的所有内容放入/tmp/foo

    【讨论】:

    • 谢谢,我现在明白了……RTFM,好的。
    猜你喜欢
    • 2015-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-23
    相关资源
    最近更新 更多