Bash rsync-排除子目录以外的所有内容,但排除子目录
我正在尝试将远程目录rsync到本地,我想排除除子目录之外的所有内容。但该子目录中有一个子目录,我想将其排除在外。我的理解是rsync在排除之后应用include,我试图找出必要的模式。以下是我要传递的包含/排除标志:Bash rsync-排除子目录以外的所有内容,但排除子目录,bash,rsync,Bash,Rsync,我正在尝试将远程目录rsync到本地,我想排除除子目录之外的所有内容。但该子目录中有一个子目录,我想将其排除在外。我的理解是rsync在排除之后应用include,我试图找出必要的模式。以下是我要传递的包含/排除标志: rsync -Pav -e "ssh -i /path/to/key.pem" \ --include="subdir/***" \ --exclude="subdir/subsubdir" \ --exclude="*" \ remote@address.com
rsync -Pav -e "ssh -i /path/to/key.pem" \
--include="subdir/***" \
--exclude="subdir/subsubdir" \
--exclude="*" \
remote@address.com:/path/to/remote/dir/ \
/path/to/local/dir/
编辑:这会导致rsync获取subdir中的所有内容,包括我试图排除的subsubdir
谢谢大家! 我关于rsync如何应用过滤器的假设是错误的@meuh留下了正确答案的评论:
rsync按照您给定的顺序应用过滤器,因此请在include之前尝试subsubsub exclude 我还必须在排除项中添加一个尾随斜杠。以下是正确的rsync命令:
rsync -Pav -e "ssh -i /path/to/key.pem" \
--exclude="subdir/subsubdir/" \
--include="subdir/***" \
--exclude="*" \
remote@address.com:/path/to/remote/dir/ \
/path/to/local/dir/
下面是本地运行的命令的演示:
rsync -Pav \
--exclude="subdir/subsubdir/"
--include="subdir/***" \
--exclude="*" \
./remote/ \
./local/
之前:
.
├── local
└── remote
├── subdir
│ ├── subsubdir
│ │ └── test.txt
│ └── test.txt
└── test.txt
之后:
.
├── local
│ └── subdir
│ └── test.txt
└── remote
├── subdir
│ ├── subsubdir
│ │ └── test.txt
│ └── test.txt
└── test.txt
当前的行为是什么?它获取subdir中的所有内容,包括被排除的subdirrsync按您给定的顺序应用过滤器,所以请在include之前尝试subsubsub exclude。@meuh好吧。。。就是这样:)而且我还必须将尾部斜杠添加到排除的细分曲面。你想把它写下来作为答案,我会把它标对吗?