日期:2014-05-16  浏览次数:20719 次

我使用过的Linux命令之du - 查看文件的磁盘空间占用情况

我使用过的Linux命令之du - 查看文件的磁盘空间占用情况

本文链接:http://codingstandards.iteye.com/blog/786427 ?? (转载请注明出处)

用途说明

du命令是用来查看磁盘空间占用情况的,在Linux系统维护时常会用到,并且通常与df命令搭配使用。首先使用df看一下各个磁盘分区的占用情况,如果某个分区的占用超过一定百分比(比如80%),就认为该分区应该清理一下了。如果不太确定从哪里下手清理,就可以使用du来统计一下各个目录的磁盘占用情况,找到磁盘占用大的目录。一般情况下,程序日志占用的空间会比较多,Web上传产生的临时文件,导出数据时生成的数据文件,还有就是数据库也会随着时间而不断增长。

常用参数

-s 显示总数量。

-h 显示的数量更好看些,比如用K/M/G表示大小。

--max-depth=N 统计的目录深度。当N=0时等同于-s,所以和--s参数不能同时出现。

-b 显示为字节数。

-k 显示为K字节数。

-m 显示为兆字节数。

使用示例

示例一 查看/var的磁盘使用情况

[root@jfht ~]# df
文件系统?????????????? 1K-块??????? 已用???? 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
???????????????????? 966221844? 25612844 890736104?? 3% /
/dev/cciss/c0d0p1?????? 493891???? 16888??? 451504?? 4% /boot
tmpfs????????????????? 2074392???????? 0?? 2074392?? 0% /dev/shm
[root@jfht ~]# df /var
文件系统?????????????? 1K-块??????? 已用???? 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
???????????????????? 966221844? 25612848 890736100?? 3% /
[root@jfht ~]# du /var
8?????? /var/games
8?????? /var/local
8?????? /var/spool/at/spool
24????? /var/spool/at
16????? /var/spool/cron
8?????? /var/spool/lpd
8?????? /var/spool/clientmqueue
8?????? /var/spool/repackage
8?????? /var/spool/vbox
8?????? /var/spool/mqueue
8?????? /var/spool/cups/tmp
16????? /var/spool/cups
52004?? /var/spool/mail
32????? /var/spool/anacron
52140?? /var/spool
8?????? /var/yp/binding
24????? /var/yp
8?????? /var/db/nscd
28????? /var/db
16????? /var/empty/sshd/etc
24????? /var/empty/sshd
32????? /var/empty
8?????? /var/ftp/pub
16????? /var/ftp
8?????? /var/tmp
8?????? /var/cvs
8?????? /var/gdm
8884??? /var/log/sa
12????? /var/log/pm
8?????? /var/log/conman
36????? /var/log/prelink
15880?? /var/log/audit
8?????? /var/log/gdm
8?????? /var/log/vbox
8?????? /var/log/ppp
8?????? /var/log/conman.old
8?????? /var/log/samba
20????? /var/log/setroubleshoot
20????? /var/log/cups
16????? /var/log/mail
744404? /var/log
8?????? /var/lock/lvm
8?????? /var/lock/dmraid
176???? /var/lock/subsys
204???? /var/lock
8?????? /var/crash
8?????? /var/nis
8?????? /var/run/netreport
8?????? /var/run/sudo
8?????? /var/run/wpa_supplicant
8?????? /var/run/pm
8?????? /var/run/mdmpd
8?????? /var/run/winbindd
8?????? /var/run/mdadm
8?????? /var/run/nscd
8?????? /var/run/ppp
12????? /var/run/dbus
12????? /var/run/setrans
20????? /var/run/avahi-daemon
12????? /var/run/screen/S-root
20????? /var/run/screen
12????? /var/run/setroubleshoot
16????? /var/run/cups/certs
28????? /var/run/cups
8?????? /var/run/NetworkManager
8?????? /var/run/saslauthd
8?????? /var/run/console
492???? /var/run
8?????? /var/preserve
8?????? /var/opt
8?????? /var/cache/logwatch
8?????? /var/cache/yum
8?????? /var/cache/coolkey
8?????? /var/cache/foomatic
8?????? /var/cache/alchemist
332???? /var/cache/fontconfig
8?????? /var/cache/man/cat6
8?????? /var/cache/man/cat4
8?????? /var/cache/man/X11R6/cat6
8?????? /var/cache/man/X11R6/cat4
8?????? /var/cache/man/X11R6/cat3
8?????? /var/cache/man/X11R6/catn
8?????? /var/cache/man/X11R6/cat1
8?????? /var/cache/man/X11R6/cat5
8?????? /var/cache/man/X11R6/cat2
8?????? /var/cache/man/X11R6/cat8
8?????? /var/cache/man/X11R6/cat9
8?????? /var/cache/man/X11R6/cat7
88????? /var/cache/man/X11R6
8?????? /var/cache/man/local/cat6
8?????? /var/cache/man/local/cat4
8?????? /var/cache/man/local/cat3
8?????? /var/cache/man/local/catn
8?????? /var/cache/man/loca