美文网首页
4-10.14 Linux 中的文件同步传输 --- rsync

4-10.14 Linux 中的文件同步传输 --- rsync

作者: 捌千里路雲和月 | 来源:发表于2021-09-18 03:31 被阅读0次

--remove-source-files:删除源已经成功传输的文件。

  • 4-10.13 内容:
    通过 rsync -av ---remove-source-files 删除源已经成功传输的文件。
  • 操作步骤:
    1、创建测试用例:
    /root/test 目录下 新建 backups_remove_source_files 目录和 SRC 目录。
    SRC 目录下新建三件文件 file1.txt、file2.txt 和 file3.txt。
    命令:touch SRC/file1.txt SRC/file2.txt SRC/file3.txt
[root@localhost test]# mkdir SRC
[root@localhost test]# mkdir backups_remove_source_files
[root@localhost test]# 
[root@localhost test]# touch SRC/file1.txt SRC/file2.txt SRC/file3.txt
[root@localhost test]# tree    ## 目录结构
.
├── backups_remove_source_files
└── SRC
    ├── file1.txt
    ├── file2.txt
    └── file3.txt

2 directories, 3 files

2、通过 --remove-source-files 传输 SRC 目录下的文件到 backups_remove_source_files 目录。这个过程中会把成功传输的文件从 SRC 目录中删除。相似与 “ 剪贴 ” 文件。

## 源目录路径是 SRC/,有 / 。代表 SRC目录下的文件,不含目录本身。
[root@localhost test]# rsync -av --remove-source-files SRC/ backups_remove_source_files/
sending incremental file list    ## 从传输列表看出成功传输了三个文件。
./
file1.txt
file2.txt
file3.txt

sent 230 bytes  received 100 bytes  660.00 bytes/sec
total size is 0  speedup is 0.00
[root@localhost test]# 
[root@localhost test]# tree
.
├── backups_remove_source_files    
│   ├── file1.txt
│   ├── file2.txt
│   └── file3.txt
└── SRC    ## 成功传输三个文件后,源目录的文件会被删除。相似于把文件 “ 剪贴” 到目标目录。 

2、使用 --remove-source-files 时,连同源目录传输到目标目录。传输成功后,源目录及内容会传输到目标目录。而,原来的源目录会是空目录。

## 源目录路径是 SRC,没有 / 。所以是整个目录及内容传输到目标目录。
[root@localhost test]# rsync -av --remove-source-files SRC backups_remove_source_files/
sending incremental file list    ## 传输列表可以看出源目录及文件成功传输
SRC/
SRC/file1.txt
SRC/file2.txt
SRC/file3.txt

sent 238 bytes  received 101 bytes  678.00 bytes/sec
total size is 0  speedup is 0.00
[root@localhost test]# 
[root@localhost test]# tree
.
├── backups_remove_source_files
│   └── SRC    ## 整个源目录传输到了目标目录下
│       ├── file1.txt
│       ├── file2.txt
│       └── file3.txt
└── SRC    ## 原来的源目录则还有一个空目录

3 directories, 3 files
[root@localhost test]# 

  • 这里和 windows 的 “剪贴” 目录不同,windows 的剪贴是整体移动, --remove-source-files 通过测试,传输文件是相似于剪贴过去目标目录。而传输目录则整个目录及内容传输到目标目录,仍会保留一个空的源目录。

相关文章

网友评论

      本文标题:4-10.14 Linux 中的文件同步传输 --- rsync

      本文链接:https://www.haomeiwen.com/subject/jcxuwltx.html