WEB开发网
开发学院操作系统Linux/Unix linux du df 命令详解 阅读

linux du df 命令详解

 2012-05-25 08:00:36 来源:WEB开发网   
核心提示:b:大小用bytes来表示 (默认值为k bytes)c:最后再加上总计 (默认值)s:只显示各档案大小的总合x:只计算同属同一个档案系统的档案L:计算所有的档案大小常用命令:du -a操作详解引用指令 du 能以指定的目录下的子目录为单位,显示每个目录内所有档案所占用的磁盘空间大小,linux du df 命令详解(
b:大小用bytes来表示 (默认值为k bytes)
c:最后再加上总计 (默认值)
s:只显示各档案大小的总合
x:只计算同属同一个档案系统的档案
L:计算所有的档案大小
常用命令:du -a
操作详解
引用
指令 du 能以指定的目录下的子目录为单位,显示每个目录内所有档案所占用的磁盘空间大小。例如:
# du -h /etc
104K /etc/defaults
6.0K /etc/X11
8.0K /etc/bluetooth
4.0K /etc/gnats
52K /etc/isdn
388K /etc/mail
68K /etc/mtree
2.0K /etc/ntp
38K /etc/pam.d
44K /etc/periodic/daily
6.0K /etc/periodic/monthly
42K /etc/periodic/security
16K /etc/periodic/weekly
110K /etc/periodic
6.0K /etc/ppp
318K /etc/rc.d
2.0K /etc/skel
130K /etc/ssh
10K /etc/ssl
1.7M /etc
我们目样使用 -h 参数来显示 human-readable 的格式。在应用时,我们可以使用 du 这个指令来查看哪个目录占用最多的空间。不过,du 的输出结果通常很长,我们可以加上 -s 参数来省略指定目录下的子目录,而只显示该目录的总合即可:
# du -sh /etc
1.7M /etc
在查看目录的使用情形时,我们可以将输出结果导到 sort 指令进行排序,以了解哪个档案用了最多的空间:
# du /etc | sort -nr | more
1746 /etc
388 /etc/mail
318 /etc/rc.d
130 /etc/ssh
110 /etc/periodic
104 /etc/defaults
68 /etc/mtree
52 /etc/isdn
44 /etc/periodic/daily
42 /etc/periodic/security
38 /etc/pam.d
16 /etc/periodic/weekly
10 /etc/ssl
8 /etc/bluetooth
6 /etc/ppp
6 /etc/periodic/monthly
6 /etc/X11
4 /etc/gnats
2 /etc/skel
2 /etc/ntp
sort 的参数 -nr 表示要以数字排序法进行反向排序,因为我们要对目录大小做排序,所以不可以使用 human-readable 的大小输出,不然目录大小中会有 K、M 等字样,会造成排序不正确
ls –lh 可以看出当前目录文件的大小(不含目录), 比如下面的的322M。
[root@LS-SVR-18 ~]# ls -lh
total 322M
-rw-r–r– 1 root root 312M Aug 1 23:35 10.50.86.18.tar.z
-rw-r–r– 1 root root 1.3K Aug 1 17:41 anaconda-ks.cfg
drwxr-xr-x 2 root root 4.0K Aug 1 21:44 Desktop
-rw-r–r– 1 root root 62K Aug 1 17:41 install.log
-rw-r–r– 1 root root 5.2K Aug 1 17:41 install.log.syslog
-rw-r–r– 1 root root 8.9M Sep 28 15:29 Install_MSN_Messenger_zhcn.EXE
-rwxr-xr-x 1 root root 9.2K Aug 16 11:20 m64
-rw-r–r– 1 root root 1.1K Aug 16 11:20 m64.c
-rw-r–r– 1 root root 1.1K Aug 8 04:33 m64.o
drwxr-xr-x 2 root root 4.0K Oct 9 15:45 MCA
drwxr-xr-x 2 root root 4.0K Oct 9 15:41 MGM
drwxr-xr-x 2 root root 4.0K Oct 9 15:45 MYSQL
-rw——- 1 root root 95 Sep 5 10:34 nohup.out
使用du -sSh 也是同样的结果
[root@LS-SVR-18 ~]# du -sSh
322M
使用du -sh 则包含了子目录的内容
[root@LS-SVR-18 ~]# du -sh
451M .
查看每个文件和目录的大小
[root@LS-SVR-18 ~]# du -sh *
313M 10.50.86.18.tar.z
8.0K anaconda-ks.cfg
8.0K Desktop
72K install.log
12K install.log.syslog
8.9M Install_MSN_Messenger_zhcn.EXE
16K m64
8.0K m64.c
8.0K m64.o
476K MCA
65M MGM
65M MYSQL
8.0K nohup.out

上一页  1 2 

Tags:linux du df

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接