Linux Rsync排除文件,目录和文件夹示例

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

Rsync命令教程与示例

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 Specific Directory
Exclude Specific Directory
排除特定目录

排除具有特定模式的多个目录(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/
LEARN MORE  Ultimate Backup Tools And Utilities List
了解更多Ultimate Backup Tools and Utilities列表

翻译自: https://www.poftut.com/linux-rsync-exclude-filedirectory-folder-examples/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值