rsync 仅文件夹,里面没有文件,也没有扫描文件

rsync only folder without files inside and without scanning files

我想使用 rsync 只同步文件夹 a 和 b 之间的文件夹

> rsync -zaSH --delete -vv --delete -f"+ f/" -f"- f/*" a/ b
sending incremental file list
[sender] showing directory f because of pattern f/
[sender] hiding file f/1.data because of pattern f/*
[sender] hiding file f/4.data because of pattern f/*
[sender] hiding file f/8.data because of pattern f/*
[sender] hiding file f/10.data because of pattern f/*
[sender] hiding file f/6.data because of pattern f/*
[sender] hiding file f/3.data because of pattern f/*
[sender] hiding file f/5.data because of pattern f/*
[sender] hiding file f/9.data because of pattern f/*
[sender] hiding file f/7.data because of pattern f/*
[sender] hiding file f/2.data because of pattern f/*
delta-transmission disabled for local transfer or --whole-file
f/
total: matches=0  hash_hits=0  false_alarms=0 data=0

sent 88 bytes  received 90 bytes  356.00 bytes/sec
total size is 0  speedup is 0.00

> tree 
.
├── a
│   └── f
│       ├── 10.data
│       ├── 1.data
│       ├── 2.data
│       ├── 3.data
│       ├── 4.data
│       ├── 5.data
│       ├── 6.data
│       ├── 7.data
│       ├── 8.data
│       └── 9.data
└── b
    └── f

从详细输出可以看出,文件仍然被扫描。如果文件夹中有数百万个文件,则可能需要很长时间。 有没有一种方法可以在不扫描文件的情况下实现相同的目标?谢谢

您不能阻止它直接扫描 a/f/ 中的文件,但它不应扫描这些文件的任何子目录,除非它们也被称为 f

此命令也将排除那些:

rsync -aSH --delete -vv --delete -f"+ /f/" -f"- /f/*" a/ b/

前缀模式 / 表示匹配源目录的根目录。

(我还删除了 -z,因为压缩对本地副本没有意义。)