gpt4 book ai didi

linux - 无法获取 rsync 排除选项以排除目录

转载 作者:IT王子 更新时间:2023-10-29 00:02:58 26 4
gpt4 key购买 nike

rsync 有问题。我将 rsync 用作美化的 cp 命令。我在脚本中有以下代码。

rsync -aL --exclude /path/to/exclude/ --exclude='.*' /source/ /destination

我可以让 rsync 排除任何隐藏文件。因此 '.*' 我无法排除要排除的排除目录。我试过使用 '=' 符号,用双引号和单引号将目录括起来。任何帮助将不胜感激。提前致谢。

最佳答案

实际上,Erik's 都不是也不Antoni's答案完全准确。

Erik 说对了一半

As test/a is the base directory synced from, the exclude pattern is specified by starting with a/

排除模式的 root 确实是 test/a(即模式 /some/path 绑定(bind)到 test/a/some/path),但这还不是全部。

来自手册页:

if the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files, otherwise it is matched against the end of the pathname. This is similar to a leading ^ in regular expressions. Thus "/foo" would match a file named "foo" at either the"root of the transfer" (for a global rule) or in the merge-file's directory (for a per-directory rule).

我们可以忽略 per-directory 位,因为它不适用于我们这里。

因此,rsync -nvraL test/a test/dest --exclude=a/b/c/d 肯定会排除 test/a/b/c/d(和 child ),但它也会排除 test/a/other/place/a/b/c/d

rsync -nvraL test/a test/dest --exclude=/b/c/d,另一方面,将排除 test/a/b/c/d(和子级)(test/a/ 锚定的点)。

这就是为什么如果您想从备份中排除那个特定路径,您仍然需要锚定初始斜线。这可能看起来像是一个小细节,而且您的排除模式变得越具体(例如 Pictureshome/daniel/Pictures),但它可能会出现到处咬你的屁股。

关于linux - 无法获取 rsync 排除选项以排除目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5343558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com