您的位置:首页 > 运维架构 > Linux

每天一个Linux之du命令

2016-01-06 20:10 627 查看
Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的。

1、命令格式:
du [选项][文件]

2、命令功能:
显示每个文件和目录的磁盘使用空间

3、命令参数:
-s或--summarize 仅显示总计,只列出最后加总的值
-h或--human-readable 以K,M,G为单位,提高信息的可读性

4、使用实例:
实例1:显示目录或者文件所占空间
命令:
du 和 du -h
输出:
[BEGIN] 2016/1/6 19:42:23
[root@DS-CentOS44 ~]# ls -al
总用量 148
dr-xr-x---.  6 root root  4096 1月   6 16:40 .
dr-xr-xr-x. 26 root root  4096 1月   5 23:45 ..
drwxr-xr-x   2 root root  4096 1月   6 16:40 a
-rw-------.  1 root root  9421 12月 31 16:54 anaconda-ks.cfg
drwxr-xr-x   2 root root  4096 1月   6 16:40 b
-rw-------   1 root root   652 1月   6 10:20 .bash_history
-rw-r--r--.  1 root root    18 5月  20 2009 .bash_logout
-rw-r--r--.  1 root root   176 5月  20 2009 .bash_profile
-rw-r--r--.  1 root root   272 12月 31 16:55 .bashrc
drwxr-xr-x   2 root root  4096 1月   6 16:40 c
-rw-r--r--.  1 root root   100 9月  23 2004 .cshrc
-rw-r--r--   2 root root  1026 1月   6 16:32 fstab1
lrwxrwxrwx   1 root root     6 1月   6 16:36 fstab2 -> fstab1
-rw-r--r--   2 root root  1026 1月   6 16:32 fstab3
-rw-r--r--.  1 root root 44933 12月 31 16:54 install.log
-rw-r--r--.  1 root root 10260 12月 31 16:50 install.log.syslog
-rw-r--r--.  1 root root  4149 7月   9 17:40 .screenrc
drwx------.  2 root root  4096 12月 31 16:54 .ssh
-rw-r--r--.  1 root root   129 12月  4 2004 .tcshrc
-rw-------   1 root root   939 1月   6 09:05 .viminfo
-rw-r--r--.  1 root root  4546 7月  16 17:33 .vimrc
[root@DS-CentOS44 ~]# du /root
8	/root/.ssh
4	/root/c
4	/root/b
4	/root/a
144	/root
[root@DS-CentOS44 ~]# du -h /root
8.0K	/root/.ssh
4.0K	/root/c
4.0K	/root/b
4.0K	/root/a
144K	/root

[END] 2016/1/6 19:42:53
说明:du显示当前目录以及当前目录下的所有目录存储大小,存储单位并未有显示,加上选项-h显示的是默认存储单位。

实例2:显示指定文件所占空间
命令:
du .ssh
输出:
[BEGIN] 2016/1/6 20:06:46
[root@DS-CentOS44 ~]# ls -al
总用量 148
dr-xr-x---.  6 root root  4096 1月   6 16:40 .
dr-xr-xr-x. 26 root root  4096 1月   5 23:45 ..
drwxr-xr-x   2 root root  4096 1月   6 16:40 a
-rw-------.  1 root root  9421 12月 31 16:54 anaconda-ks.cfg
drwxr-xr-x   2 root root  4096 1月   6 16:40 b
-rw-------   1 root root   652 1月   6 10:20 .bash_history
-rw-r--r--.  1 root root    18 5月  20 2009 .bash_logout
-rw-r--r--.  1 root root   176 5月  20 2009 .bash_profile
-rw-r--r--.  1 root root   272 12月 31 16:55 .bashrc
drwxr-xr-x   2 root root  4096 1月   6 16:40 c
-rw-r--r--.  1 root root   100 9月  23 2004 .cshrc
-rw-r--r--   2 root root  1026 1月   6 16:32 fstab1
lrwxrwxrwx   1 root root     6 1月   6 16:36 fstab2 -> fstab1
-rw-r--r--   2 root root  1026 1月   6 16:32 fstab3
-rw-r--r--.  1 root root 44933 12月 31 16:54 install.log
-rw-r--r--.  1 root root 10260 12月 31 16:50 install.log.syslog
-rw-r--r--.  1 root root  4149 7月   9 17:40 .screenrc
drwx------.  2 root root  4096 12月 31 16:54 .ssh
-rw-r--r--.  1 root root   129 12月  4 2004 .tcshrc
-rw-------   1 root root   939 1月   6 09:05 .viminfo
-rw-r--r--.  1 root root  4546 7月  16 17:33 .vimrc
[root@DS-CentOS44 ~]# du .ssh
8	.ssh
[root@DS-CentOS44 ~]# du -h .ssh
8.0K	.ssh

[END] 2016/1/6 20:07:07


实例3:只显示总和的大小
命令:
du -s
输出:
[BEGIN] 2016/1/6 20:08:35
[root@DS-CentOS44 ~]#
[root@DS-CentOS44 ~]# du -s /root
144	/root
[root@DS-CentOS44 ~]#
[root@DS-CentOS44 ~]# du -s /root
144	/root
[root@DS-CentOS44 ~]# du -sh /root
144K	/root

[END] 2016/1/6 20:08:48
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  命令 Linux 每天一个