linux下快速刪除大量檔案

來源:互聯網
上載者:User


linux下快速刪除大量檔案 假如你要在linux下刪除大量檔案,比如100萬、1000萬,像/var/spool/clientmqueue/的mail郵件,  像/usr/local/nginx/proxy_temp的nginx緩衝等,那麼rm -rf *可能就不好使了。 rsync提供了一些跟刪除相關的參數   www.2cto.com  rsync --help | grep delete      --del                   an alias for --delete-during      --delete                delete files that don't exist on the sending side      --delete-before         receiver deletes before transfer (default)      --delete-during         receiver deletes during transfer, not before      --delete-after          receiver deletes after transfer, not before      --delete-excluded       also delete excluded files on the receiving side      --ignore-errors         delete even if there are I/O errors      --max-delete=NUM        don't delete more than NUM files  其中--delete-before    接收者在傳輸之前進行刪除操作 
 可以用來清空目錄或檔案,如下: 1、先建立一個空目錄 mkdir /data/blank 2、用rsync刪除目標目錄 rsync --delete-before -d /data/blank/ /var/spool/clientmqueue/ 這樣目標目錄很快就被清空了  又假如你有一些特別大的檔案要刪除,比如nohup.out這樣的即時更新的檔案,動輒都是幾十個G上百G的,也可   www.2cto.com   以用rsync來清空大檔案,而且效率比較高 1、建立空檔案 touch /data/blank.txt 2、用rsync清空檔案 rsync -a --delete-before --progress --stats /root/blank.txt /root/nohup.out building file list ... 1 file to consider blank.txt            0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)  Number of files: 1 Number of files transferred: 1 Total file size: 0 bytes Total transferred file size: 0 bytes Literal data: 0 bytes Matched data: 0 bytes File list size: 27 File list generation time: 0.006 seconds File list transfer time: 0.000 seconds Total bytes sent: 73 Total bytes received: 31   www.2cto.com  sent 73 bytes  received 31 bytes  208.00 bytes/sec total size is 0  speedup is 0.00  tips: 當SRC和DEST檔案性質不一致時將會報錯 當SRC和DEST性質都為檔案【f】時,意思是清空檔案內容而不是刪除檔案 當SRC和DEST性質都為目錄【d】時,意思是刪除該目錄下的所有檔案,使其變為空白目錄 最重要的是,它的處理速度相當快,處理幾個G的檔案也就是秒級的事 最核心的內容是: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.