加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

rsync – 排除除少数之外的所有目录

发布时间:2020-12-14 03:02:03 所属栏目:Linux 来源:网络整理
导读:似乎有很多关于此问题的SF和SO问题,但似乎没有一个符合我的要求. source_dir/ some_dir/ another_dir/ some_file.php some_other_file.txt include_this_dir/ include_that_dir/ yet_another_dir/ 所以我想rsync其中两个dirs,而排除其余的.重要的是我们要排
似乎有很多关于此问题的SF和SO问题,但似乎没有一个符合我的要求.
source_dir/
  some_dir/
  another_dir/
  some_file.php
  some_other_file.txt
  include_this_dir/
  include_that_dir/
  yet_another_dir/

所以我想rsync其中两个dirs,而排除其余的.重要的是我们要排除除了这两个目录之外的所有目录,因为可能有其他文件稍后会被添加到source_dir中,并且需要在未明确列出的情况下被排除.

我试过了:

rsync -av --dry-run --delete --exclude="source_dir/*" (or just "*") --include-from="include.txt" source_dir dest_dir

我的include.txt有

include_this_dir/
  include_that_dir/

我还尝试添加

source_dir/

没有快乐.根本没有包含任何东西.

解决方法

一个简单的过滤器应该可以做到.使用适当的示例构建先前的答案 – 明确地包括父(s),以及所有(**)子文件夹和文件.然后排除其他一切.这是filter.txt:
+ /include_this_dir/
+ /include_this_dir/**
+ /include_that_dir/
+ /include_that_dir/**
- /**

使用命令行:

rsync -av --dry-run --filter="merge filter.txt" source_dir/ dest_dir/

会导致:

sending incremental file list
created directory dest_dir
./
include_that_dir/
include_that_dir/somefile.txt
include_that_dir/subdir/
include_this_dir/

sent 202 bytes  received 65 bytes  534.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读