迹忆客 专注技术分享

当前位置:主页 > 学无止境 > 操作系统 >

Rsync 在 Linux 中排除文件和目录

作者:迹忆客 最近更新:2023/03/17 浏览次数:

rsync 是一个强大的命令行工具,用于使用远程 shell 在两个站点之间同步文件和目录。

使用 rsync 命令,你可以在系统之间复制数据和文件并进行额外备份。

此外,你可以根据名称和位置从数据副本中排除一个或多个文件或文件夹。

在 Linux 中排除具有指定扩展名的所有文件

也可以排除具有指定扩展名的文件。运行以下命令以排除所有带有 .txt 扩展名的文件,例如:

$ rsync -avz --exclude=*.txt source/ destination

输出:

sending incremental file list
thanosdir2/thanosdir3/

sent 203 bytes  received 20 bytes  446.00 bytes/sec
total size is 0  speedup is 0.00

在 Linux 中使用 -exclude 选项排除特定目录

也可以禁止从指定目录执行同步或复制操作。目录名称是使用 -exclude 选项指定的。

在下面的示例中,我们将从列表中排除目录 thanosdir

$ rsync -avrz --exclude=thanosdir3 source/ destination

输出:

sending incremental file list
created directory destination
./
thanos.txt
thanos1.txt
thanos2.txt
thanosdir/
thanosdir/thanosdir1/
thanosdir2/
thanosdir4/

sent 391 bytes  received 130 bytes  1,042.00 bytes/sec
total size is 0  speedup is 0.00

在 Linux 中排除多个目录

你还可以过滤掉任何符合特定模式的目录。例如,应排除 source 下以字母 t 开头的任何目录:

$ rsync -avrz --exclude=t* source/ destination

输出:

sending incremental file list

sent 56 bytes  received 12 bytes  136.00 bytes/sec
total size is 0  speedup is 0.00

如输出所示,所有带有字母 t 的目录都被排除在外。

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便