在運維的工作中、有時我們需要去刪除大文件、或者 N (N 取正無窮喲~~)多小文件
那麼、rm 次奧咯、
這裡、Rocky 介紹 Linux 史上最可愛、最溫柔、最成熟、最善良、最.....槽糕、找不到形容詞、囧
那便是 rsync 的另外一種用法
① 語法:
# rsync --delete-before -avH --progress --stats DEST SRC
解釋:
當SRC和DEST性質都為文件【f】時,意思是清空文件內容而不是刪除文件
當SRC和DEST性質都為目錄【d】時,意思是刪除該目錄下的所有文件,使其變為空目錄
PS:其實該命令頂好記的哦、av -_-#、H$_$、男人很少不懂的、騷年、此時你的硬盤都有誰來著、、
② 原理:
rsync實際上用的就是替換原理
③ 優點:
處理速度相當快,處理幾個G的文件也就是秒級的事、比rm要快很多倍
④ 缺點:
對磁盤io的占用較高、業務高峰或要暫避
⑤ 測試:
[root@localhost log]# ls
rhel-server-5.8-i386-dvd.iso
[root@localhost log]# pwd
/tmp/test/log
[root@localhost ~]# mkdir empty
[root@localhost ~]# rsync --delete-before -avH --progress --stats /root/empty/ /tmp/test/log/
building file list ...
1 file to consider
deleting rhel-server-5.8-i386-dvd.iso
./
Number of files: 1
Number of files transferred: 0
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 19
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 29
Total bytes received: 15
sent 29 bytes received 15 bytes 6.77 bytes/sec
total size is 0 speedup is 0.00