rsync使用include选项仅复制某些类型的文件 [英] rsync copy over only certain types of files using include option

查看:353
本文介绍了rsync使用include选项仅复制某些类型的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下bash脚本仅复制某些扩展名的文件(在本例中为* .sh),但是仍会复制所有文件.怎么了?

I use the following bash script to copy only files of certain extension(in this case *.sh), however it still copies over all the files. what's wrong?


from=$1
to=$2

rsync -zarv  --include="*.sh" $from $to

推荐答案

我认为--include用于包含文件的子集,这些文件被--exclude排除在外,而不是仅包括那些文件. 换句话说:您必须考虑 include 的含义,即不排除.

I think --include is used to include a subset of files that are otherwise excluded by --exclude, rather than including only those files. In other words: you have to think about include meaning don't exclude.

请尝试:

rsync -zarv  --include "*/" --exclude="*" --include="*.sh" "$from" "$to"

对于rsync 3.0.6或更高版本,需要对订单进行如下修改(请参见注释):

For rsync version 3.0.6 or higher, the order needs to be modified as follows (see comments):

rsync -zarv --include="*/" --include="*.sh" --exclude="*" "$from" "$to"

添加-m标志将避免在目标位置创建空目录结构.在3.1.2版中进行了测试.

Adding the -m flag will avoid creating empty directory structures in the destination. Tested in version 3.1.2.

因此,如果我们只希望* .sh文件,则必须排除所有文件--exclude="*",包括所有目录--include="*/",并包括所有* .sh文件--include="*.sh".

So if we only want *.sh files we have to exclude all files --exclude="*", include all directories --include="*/" and include all *.sh files --include="*.sh".

您可以在 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆