我正在尝试从
rsync
进程中排除一些目录和隐藏目录。
我注意到 rsync
--exclude
标志有以下行为:
以下不包括 .git 目录。
""
是必不可少的。
rsync -av --exclude=".git" ./data ./scratch
以下不包括Test_Data目录
rsync -av --exclude=./data/Test_Data/ ./data ./scratch
但是,将两者结合起来包括 Test_Data 目录,但仍然不包括 .git 目录
rsync -av --exclude=".git" --exclude=./data/Test_Data/ ./data ./scratch
交换顺序仍然排除 .git 目录并包含 Test_Data
rsync -av --exclude="./data/Test_Data/" --exclude=".git" ./data ./scratch
我测试了单
''
或双""
或不带引号的变体。我还测试了语法:
--exclude={"./data/Test_Data/",".git"}
而且性能是一样的。使用 rsync 排除隐藏目录和目录的正确方法是什么,或者这是不可能的?
目录结构示例:
scratch1/dir1/
scratch1/dir2/dir1/
scratch1/.test/
--exclude
匹配所有名为 .test/
和 dir1/
的目录。结尾的 /
表示避免任何同名文件的目录。
rsync -av --exclude .test/ --exclude dir1/ ./scratch1 ./scratch2
在这种情况下,仅包含
scratch1/dir2/
,并且排除 dir1
和 dir2/dir1
。
按路径匹配是相对于
/scratch1/
:
--exclude /dir1/
仅匹配 scratch1/dir1/
rsync -av --exclude .test/ --exclude /dir1/ ./scratch1/ ./scratch2/scratch1
在这种情况下,排除
scratch1/dir1
,并包括 scratch1/dir2/dir1/
。请注意,相对路径需要 /
上的尾随 ./scratch1/
。
以下帖子也提供了更多详细信息:
https://unix.stackexchange.com/questions/5774/how-to-exclude-subdirectory-from-rsync