Rsync is very popular and powerful tool used for backup and clone operations. Rsync can work in localhost or remote hosts. This makes rsync very flexible. We have all ready provided some introduction in the following tutorial.
Rsync是非常流行且功能强大的工具,用于备份和克隆操作。 Rsync可以在localhost或远程主机上工作。 这使rsync非常灵活。 我们都准备在以下教程中提供一些介绍。
Rsync Command Tutorial With Examples
In this tutorial we will look exclude operations in detail. Exclude feature provides a lot of different use cases. We will look most useful of them.
在本教程中,我们将详细介绍排除操作。 排除功能提供了许多不同的用例。 我们将在其中找到最有用的。
排除特定目录 (Exclude Specific Directory)
One of the most useful use case for exclude feature is excluding given directories. In this example we will exclude directories those names starts with vms
.
排除功能最有用的用例之一是排除给定目录。 在此示例中,我们将排除以vms
开头的目录。
$ rsync --exclude 'vms' /home/ismail/Downloads/ /home/ismail/Public/

排除具有特定模式的多个目录(Exclude Multiple Directories with Specific Pattern)
In previous example we have provided only one directory for exclude. We can also provide multiple directories for exclude. We will use wildcard. We will also use wildcard *
to complete vms
directory name.
在前面的示例中,我们仅提供了一个要排除的目录。 我们还可以提供多个排除目录。 我们将使用通配符。 我们还将使用通配符*
来完成vms
目录名。
$ rsync --exclude 'vms*' /home/ismail/Downloads/ /home/ismail/Public/
排除特定文件 (Exclude Specific File)
We can exclude specific file by providing its relative path. In this example we will exclude file named file1
.
我们可以通过提供其相对路径来排除特定文件。 在此示例中,我们将排除名为file1
。
$ rsync --exclude '/home/ismail/Downloads/file1' Downloads/ Public/
排除相对路径 (Exclude Relative Path)
Like previous example we will exlude given relative path completely. In this example we will exclude path /home/ismail/Downloads/vms
from sync operation.
像前面的示例一样,我们将完全排除给定的相对路径。 在此示例中,我们将从同步操作中排除路径/home/ismail/Downloads/vms
。
$ rsync --exclude '/home/ismail/Downloads/vms' Downloads/ Public/
排除特定文件类型 (Exclude Specific File Type)
We can also specify the file type or extension we want to exclude from sync operation. We will provide the exclude file name like *.txt
which means exclude txt
extension files.
我们还可以指定要从同步操作中排除的文件类型或扩展名。 我们将提供排除文件名,例如*.txt
,这意味着排除txt
扩展名文件。
$ rsync --exclude '*.txt' Downloads/ Public/
同时排除多个文件和目录 (Exclude Multiple Files and Directories At The Same Time)
Up to now we have used only single exclude
option. What will be if we want to exclude multiple files or directories. Actually we can use multiple exclude
options to exclude multiple files and directories. In this example we will exclude vms
directories and *.tmp
temp files.
到目前为止,我们仅使用了单个exclude
选项。 如果我们要排除多个文件或目录,该怎么办。 实际上,我们可以使用多个exclude
选项来排除多个文件和目录。 在此示例中,我们将排除vms
目录和*.tmp
临时文件。
$ rsync --exclude '*.tmp' --exclude 'vms' Downloads/ Public/
翻译自: https://www.poftut.com/linux-rsync-exclude-filedirectory-folder-examples/