--exclude参数

有时,我们希望同步时排除某些文件或目录,这时可以用--exclude参数指定排除模式。

$ rsync -av --exclude='*.txt' source/ destination
# 或者
$ rsync -av --exclude '*.txt' source/ destination

上面命令排除了所有 TXT 文件。

注意,rsync 会同步以“点”开头的隐藏文件,如果要排除隐藏文件,可以这样写--exclude=".*"

如果要排除某个目录里面的所有文件,但不希望排除目录本身,可以写成下面这样。

$ rsync -av --exclude 'dir1/*' source/ destination

多个排除模式,可以用多个--exclude参数。

$ rsync -av --exclude 'file1.txt' --exclude 'dir1/*' source/ destination

多个排除模式也可以利用 Bash 的大扩号的扩展功能,只用一个--exclude参数。

$ rsync -av --exclude={'file1.txt','dir1/*'} source/ destination

如果排除模式很多,可以将它们写入一个文件,每个模式一行,然后用--exclude-from参数指定这个文件。

$ rsync -av --exclude-from='exclude-file.txt' source/ destination
© 2017~ 随风逐叶 all right reserved,powered by Gitbook文章修订时间: 2021-04-25 12:06:52

results matching ""

    No results matching ""