Linux搜尋或尋找超過指定大小的檔案?

來源:互聯網
上載者:User

尋找超過 10MB 的檔案

 代碼如下 複製代碼

find . -type f -size +10000k -exec ls -lh {} ; | awk ‘{ print $9 “: ” $5 }’

find 路徑 -size +2000k -print

這樣可以將指定路徑內,大於2000K的檔案全部列印出來(小於用減號),根據需要篩選,提升速度和頻寬。如果你想加上一個時間,可以在後面寫 -and -mtime -1 ,表示一天24小時內有變化的檔案。


linux下的find命令用來尋找檔案,通過man find就知道它是無所不能的。所以按照檔案大小來尋找檔案就不在話下。從man find搜尋size,可以看到如下資訊:

-size n[cwbkMG]
   File uses n units of space.  The following suffixes can be used:

   b    for 512-byte blocks (this is the default if no suffix is used)

   c    for bytes

   w    for two-byte words

   k    for Kilobytes (units of 1024 bytes)

   M    for Megabytes (units of 1048576 bytes)

   G    for Gigabytes (units of 1073741824 bytes)

注意:預設單位是b,而它代表的是512位元組,所以2表示1K,1M則是2048,如果不想自己轉換,可以使用其他單位,如c、K、M等。

例子:尋找目前的目錄下檔案大小為2048(2k)位元組的檔案

find ./ -size 4
或
find ./ -size 2048c
或
find ./ -size 2K上述尋找檔案是等於指定大小的,那能不能查詢大於或小於某個指定值的檔案呢,答案是肯定,例如:

尋找大於2K的檔案,+ 表示大於
find ./ -size +2048c

尋找小於2K的檔案,- 表示小於
find ./ -size +2048c -type f

聯繫我們

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