天天看點

centos中查找出大檔案指令彙總

在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

本文轉自 guowang327 51CTO部落格,原文連結:xxxhttp://blog.51cto.com/guowang327/1732386xxxx,如需轉載請自行聯系原作者

繼續閱讀