秒刪海量資料檔案的方法

來源:互聯網
上載者:User

在營運的工作中、有時我們需要去刪除大檔案、或者 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

推薦閱讀:

rsync同步完整配置

利用rsync工具進行同步Windows和Linux機器之間的檔案

Rsync+inotify 組合使用同步方案

Rsync和inotify檔案即時備份配置

CentOS 5.5下Rsync提示與許可權問題解讀

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.