bash rsync --include 选项不排除其他文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14655834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 23:17:38  来源:igfitidea点击:

rsync --include option does not exclude other files

bashrsync

提问by user121196

trying to rsync files of certain extension(*.sh), but the bash script below still transfer all the files, why?

尝试 rsync 某些扩展名 (*.sh) 的文件,但下面的 bash 脚本仍然传输所有文件,为什么?

from=/home/xxx
rsync -zvr --include="*.sh" $from/*  root@$host:/home/tmp/

采纳答案by JohnQ

You need to add a --exclude all and it has to come after the --include

您需要添加一个 --exclude all 并且它必须在 --include 之后

rsync -zvr --include="*.sh" --exclude="*" $from/*  root@$host:/home/tmp/

回答by that other guy

--includeis for which files you want to not --exclude. Since you haven't excluded any in future arguments, there's no effect. You can do:

--include是您不想要的文件--exclude。由于您没有在未来的参数中排除任何内容,因此没有任何效果。你可以做:

from=/home/xxx
rsync -zvr --include="*.sh" --include="*/" --exclude="*" "$from" root@$host:/home/tmp/

To recursively copy all .sh files (the extra --includeto not skip directories that could contain .sh files)

递归复制所有 .sh 文件(额外--include避免跳过可能包含 .sh 文件的目录)

回答by estevo

I fixed the problem changing --exclude=*by --exclude=*.*, I understand that * exclude folder where include files are.

我通过--exclude=*.*解决了更改--exclude=*的问题,我知道 * exclude 包含文件所在的文件夹。

回答by lbutlr

On thing to add, at least on my machines (FreeBSD and OS X), this does not work:

要补充一点,至少在我的机器(FreeBSD 和 OS X)上,这不起作用:

rsync -aP --include=*/ --include=*.txt --exclude=* * /path/to/dest

but this does:

但这确实:

rsync -aP --include=*/ --include=*.txt --exclude=* . /path/to/dest

Yes, wildcarding the current directory seem to override the exclude.

是的,通配当前目录似乎覆盖排除。