centos中尋找出大檔案命令匯總

來源:互聯網
上載者:User

標籤:centos7

在linux中簡單的尋找檔案與目錄大小很簡單

#已易讀的格式顯示指定目錄或檔案的大小,-s選項指定對於目錄不詳細顯示每個子目錄或檔案的大小

du -sh [dirname|filename]

 

如:

 

目前的目錄的大小:

 代碼如下複製代碼

du -sh .

 

目前的目錄下個檔案或目錄的大小:

 代碼如下複製代碼

du -sh *

 

顯示前10個佔用空間最大的檔案或目錄:

 代碼如下複製代碼

du -s * | sort -nr | head

* -h已易讀的格式顯示指定目錄或檔案的大小

* -s選項指定對於目錄不詳細顯示每個子目錄或檔案的大小

如何在目錄中找出所有大檔案?

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等

A.

1) 句法 for RedHat / CentOS / Fedora Linux

 代碼如下複製代碼

find {/path/to/directory/} -type f -size +{size-in-kb}k -exec ls -lh {} ; | awk ‘{ print $9 “: ” $5 }’

執行個體:

尋找目前的目錄下大於50MB的檔案

 代碼如下複製代碼

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

尋找目錄/var/log大於100MB的檔案

 代碼如下複製代碼

# find /var/log -type f -size +100000k -exec ls -lh {} ; | awk ‘{ print $9 “: ” $5 }’

2)句法 for Debian / Ubuntu Linux

find {/path/to/directory} -type f -size +{file-size-in-kb}k -exec ls -lh {} ; | awk ‘{ print $8 “: ” $5 }’

執行個體:

尋找目前的目錄下大於10MB的檔案

 代碼如下複製代碼

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

Sample output:

./.kde/share/apps/akregator/Archive/http___blogs.msdn.com_MainFeed.aspx?Type=AllBlogs.mk4: 91M

./out/out.tar.gz: 828M

./.cache/tracker/file-meta.db: 101M

./ubuntu-8.04-desktop-i386.iso: 700M

./vivek/out/mp3/Eric: 230M

列出家目錄下檔案大小小於500b的檔案:

 代碼如下複製代碼

$ find $HOME -size -500b

OR

$ find ~ -size -500b

列出根目錄下大小是20 512-byte blocks的檔案:

 代碼如下複製代碼

# find / -size 20


centos中尋找出大檔案命令匯總

相關文章

聯繫我們

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