Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 大量文件刪除實測:rsync vs rm vs find 效能大比拚

編輯:Linux 教學

網傳「rsync 刪除大量文件比 rm、find 快得多」,但鮮有實測數據支撐。本文在真實環境下對比多種刪除方式,揭示真相。

測試環境與數據準備

  • 硬體:SATA 硬碟、Intel Pentium D 3.20GHz、4GB 記憶體
  • 系統:CentOS 6.2、Kernel 2.6.32、EXT4 檔案系統(noatime 掛載)
  • 工具:rsync 3.0.6
  • 測試數據:16 × 256 目錄結構,每目錄 250 個 300 字節小文件,共 1,024,000 文件

生成腳本(PHP):

for($i=0; $i<=0xF; $i++) {
  for($j=0; $j<=0xF; $j++) {
    for($m=0; $m<=0xF; $m++) {
      $dirname = sprintf("test/%x/%x%x", $i, $j, $m);
      mkdir($dirname, 0755, TRUE);
      for($k=0; $k<250; $k++) {
        file_put_contents("$dirname/$k.html", str_repeat("111", 100));
      }
    }
  }
}

實測結果(單位:秒)

方法realusersys
find 遍歷統計35.681.569.95
rsync --delete-before -d empty/ test/73.961.9335.38
rsync -a --delete empty/ test/68.691.9235.11
find -type f -delete71.401.4834.42
find + xargs -P 16 rm -Rf(16 並發)63.161.0241.36
rm -Rf 直接遞歸刪除80.331.0732.18

結論與建議

  • 各方法耗時極其接近(63~80 秒),rsync 並無顯著優勢,網傳說法在 EXT4 上不成立。
  • 多次測試數據有波動,建議多跑取平均值。
  • 極速刪除策略:mv 目錄 目錄.bak && nice -n 20 rm -rf 目錄.bak &,mv 近乎瞬間完成,刪除放入後台低優先級執行。
  • 條件允許時,mkfs 重建檔案系統最快(慎用)。
  • 不同檔案系統(XFS、ext3)表現可能差異大,歡迎補充測試數據。

實測證實:選擇熟悉、可靠的工具即可,無需迷信「神器」。

Copyright © Windows教程網 All Rights Reserved