Linux   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了rsync – 排除除少数之外的所有目录大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

似乎有很多关于此问题的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
@R_431_10586@l size is 0  speedup is 0.00 (DRY RUN)

大佬总结

以上是大佬教程为你收集整理的rsync – 排除除少数之外的所有目录全部内容,希望文章能够帮你解决rsync – 排除除少数之外的所有目录所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。