xargs與exec命令執行效率問題

來源:互聯網
上載者:User

標籤:linux   shell   

xargs,exec都是命令傳遞的過濾器,捕捉前面一個命令的結果,並將其傳遞到後一個命令。簡單點說:

  • -exec  要結合{}\;來用, {}表示前面查詢的結果\;結束符,這是固定的寫法.
  • xargs  要結合 |來操作,在處理批次檔時,速度要快些。

做了一個小實驗,統計整個Linux系統,檔案大小在1k,10k,100k之上的檔案,將其列出來:

  • 檔案大小為100k比較

[[email protected] ~]# time -p find / -size +100k | xargs ls -lart {} \;real 7.29user 1.31sys 6.89[[email protected] boot]# time -p find / -size +100k -exec ls -lart {} \;real 31.00user 6.06sys 20.88

  • 檔案大小為10比較
[[email protected] ~]# time -p find / -size +10k | xargs ls -lart {} \;real 12.43user 3.96sys 8.99[[email protected] ~]# time -p find / -size +10k -exec ls -lart {} \;real 105.14user 20.38sys 67.65

  • 檔案大小為1k的比較

[[email protected] ~]# time -p find / -size +1k | xargs ls -lart {} \;real 28.62user 5.72sys 24.01[[email protected] ~]# time -p find / -size +1k -exec ls -lart {} \;real 703.89user 129.08sys 456.97
Note:

  • 檔案比較少時,兩者的執行效率相差幾倍.
  • 檔案比較多時,兩者的執行效率相差幾十倍.


xargs與exec命令執行效率問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.