標籤: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中尋找出大檔案命令匯總