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
rsync --include option does not exclude other files
提问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
--include
is 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 --include
to 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.
是的,通配当前目录似乎覆盖排除。