linux - rsync 包含文件递归

标签 linux bash unix rsync

我只想获取新的或更改的文件列表,结果上几乎没有过滤器。 我所有新的或更改的文件是:

>f+++++++++ dsadcache.txt
>f+++++++++ root.svn
>f+++++++++ txt-file-in-root.txt
>fcsT...... wp-config.php
cd+++++++++ cache/
>f+++++++++ cache/fileincac.txt
>f+++++++++ cache/fileincache.txt
>f+++++++++ wp-content/inside.svn
>f+++++++++ wp-content/inside.txt
>f+++++++++ wp-content/object-cache.php

最终结果应如下所示:

>f+++++++++ txt-file-in-root.txt
>fcsT...... wp-config.php   
>f+++++++++ wp-content/inside.txt

当我尝试使用此规则包含文件时:

- *cache*
+ *.html
+ *.txt
+ *.js
+ *.php
+ *.jpg
+ *.jpeg
+ *.png
+ *.bmp
+ *.gif
+ *.tif
+ *.tiff
+ *.ico
+ *.json
+ *.xml
- *

过滤器可以工作,但结果不是递归的

>f+++++++++ txt-file-in-root.txt
>fcsT...... wp-config.php

缺少:

>f+++++++++ wp-content/inside.txt

我的命令是:

 rsync -nrci  --include-from="file" source/ destination

编辑:

让我解释一下获胜的答案:

这是 rsync 过程的路径顺序:

 dsadcache.txt
 txt-file-in-root.txt
 cache/
 cache/fileincac.txt
 cache/fileincache.txt
 wp-content/
 wp-content/inside.txt   
 wp-config.php

不包括

filter='+ */'

目录

cache/
wp-content/

被排除在外。

最佳答案

在递归模式下,rsync 从上到下访问子目录,因此当 rsync 检查树的顶层时,wp-content 首先与您的规则进行匹配。由于没有与此目录匹配的包含模式,通用排除规则 - * 将删除它。

根据 rsync 手册页,实现目标的一种方法是在排除规则之前的任何位置放置 + */,以便在递归操作期间包含子目录。

关于linux - rsync 包含文件递归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38276884/

相关文章:

linux - bash 脚本如何在向子进程发送信号时在非 0 退出时重启进程

regex - bash 扩展正则表达式 if 语句

linux - 用于正常运行时间监控的 Unix shell 命令

c - 如何在 xterm 中启用日志记录

python - 如何在后台运行进程并覆盖标准流

linux - 如何绕过 bash 中的 CRLF 标签?

c++ - 什么时候为 gcc 使用 -O2 标志?

python - django-jenkins - 属性错误 : 'Coverage' object has no attribute '_harvest_data'

c++ - 在进入 main() 之前我遇到段错误

mysql - Linux-SQL-如何在表的多个字段中分隔字段