--exclude参数
# --exclude参数
有时,我们希望同步时排除某些文件或目录,这时可以用--exclude
参数指定排除模式。
$ rsync -av --exclude='*.txt' source/ destination
# 或者
$ rsync -av --exclude '*.txt' source/ destination
1
2
3
2
3
上面命令排除了所有 TXT 文件。
注意,rsync 会同步以“点”开头的隐藏文件,如果要排除隐藏文件,可以这样写--exclude=".*"
。
如果要排除某个目录里面的所有文件,但不希望排除目录本身,可以写成下面这样。
$ rsync -av --exclude 'dir1/*' source/ destination
1
多个排除模式,可以用多个--exclude
参数。
$ rsync -av --exclude 'file1.txt' --exclude 'dir1/*' source/ destination
1
多个排除模式也可以利用 Bash 的大扩号的扩展功能,只用一个--exclude
参数。
$ rsync -av --exclude={'file1.txt','dir1/*'} source/ destination
1
如果排除模式很多,可以将它们写入一个文件,每个模式一行,然后用--exclude-from
参数指定这个文件。
$ rsync -av --exclude-from='exclude-file.txt' source/ destination
1
上次更新: 2023/10/17, 16:39:02