Linux 命令每天必学(34)之du命令

2019-09-23 09:22:41王振洲

0       test/log2015.log
0       test/test4/log2014.log
4.0K    test/test4/log2013.log
300K    test/test4/log2012.log
308K    test/test4
4.0K    test/scf/lib
4.0K    test/scf/service/deploy/product
4.0K    test/scf/service/deploy/info
12K     test/scf/service/deploy
16K     test/scf/service
4.0K    test/scf/doc
4.0K    test/scf/bin
32K     test/scf
4.0K    test/log2013.log
300K    test/log2012.log
0       test/log2017.log
0       test/log2016.log
4.0K    test/log30.tar.gz
4.0K    test/log.tar.bz2
4.0K    test/log.tar.gz
0       test/test3/log2014.log
4.0K    test/test3/log2013.log
8.0K    test/test3
4.0K    test/scf.tar.gz
1.3M    test
[root@localhost soft]#

说明:

实例8:显示几个文件或目录各自占用磁盘空间的大小,还统计它们的总和

命令:

du -c log30.tar.gz log31.tar.gz

输出:

[root@localhost test]# du -c log30.tar.gz log31.tar.gz
4       log30.tar.gz
4       log31.tar.gz
8       总计
[root@localhost test]#

说明:

加上-c选项后,du不仅显示两个目录各自占用磁盘空间的大小,还在最后一行统计它们的总和。

实例9:按照空间大小排序

命令:

du|sort -nr|more

输出:

[root@localhost test]# du|sort -nr|more
1288    .
608     ./test6
308     ./test4
32      ./scf
16      ./scf/service
12      ./scf/service/deploy
8       ./test3
4       ./scf/service/deploy/product
4       ./scf/service/deploy/info
4       ./scf/lib
4       ./scf/doc
4       ./scf/bin
[root@localhost test]#

说明:

实例10:输出当前目录下各个子目录所使用的空间

命令:

du -h  --max-depth=1

输出:

[root@localhost test]# du -h  --max-depth=1
608K    ./test6
308K    ./test4
32K     ./scf
8.0K    ./test3
1.3M    .