每天一(yi)個linux命令(34):du 命令
Linux du命(ming)(ming)令也是(shi)(shi)查看使用空間的(de),但是(shi)(shi)與(yu)df命(ming)(ming)令不同的(de)是(shi)(shi)Linux du命(ming)(ming)令是(shi)(shi)對文(wen)件(jian)和(he)目錄磁盤使用的(de)空間的(de)查看,還(huan)是(shi)(shi)和(he)df命(ming)(ming)令有一些區(qu)別(bie)的(de).
1.命令(ling)格式:
du [選項][文件]
2.命(ming)令功能:
顯示(shi)每(mei)個文件和目錄(lu)的磁(ci)盤(pan)使用(yong)空間。
3.命令(ling)參數(shu):
-a或(huo)-all 顯示目錄(lu)中個別(bie)文件的大小。
-b或-bytes 顯示目(mu)錄(lu)或文件(jian)大小時,以(yi)byte為單位。
-c或--total 除了顯示個別(bie)目(mu)錄或文件(jian)的大小外,同時也(ye)顯示所有目(mu)錄或文件(jian)的總和(he)。
-k或(huo)--kilobytes 以KB(1024bytes)為單(dan)位輸出。
-m或--megabytes 以MB為單位輸出。
-s或--summarize 僅顯示總計,只列(lie)出最后加總的值。
-h或--human-readable 以K,M,G為單位,提高(gao)信息(xi)的可(ke)讀(du)性。
-x或--one-file-xystem 以一開(kai)始處理時(shi)的(de)文件系統為準,若(ruo)遇上其它不(bu)同的(de)文件系統目錄則(ze)略過。
-L<符號鏈接>或(huo)--dereference<符號鏈接> 顯示選項(xiang)中(zhong)所指定符號鏈接的(de)源(yuan)文件大(da)小。
-S或--separate-dirs 顯示個別(bie)目錄(lu)的(de)大小(xiao)時,并不含其(qi)子(zi)目錄(lu)的(de)大小(xiao)。
-X<文件>或--exclude-from=<文件> 在<文件>指定目錄(lu)或文件。
--exclude=<目錄或文件(jian)> 略過指定的目錄或文件(jian)。
-D或--dereference-args 顯示指(zhi)定(ding)符(fu)號鏈接的源文件大小。
-H或--si 與(yu)-h參數相同,但(dan)是(shi)K,M,G是(shi)以1000為(wei)換算單位。
-l或--count-links 重復計算硬件鏈接的文(wen)件。
4.使用實例(li):
實例1:顯示目錄或者文件所占空間
命令(ling):
du
輸出:
[root@localhost test]# du
608 ./test6
308 ./test4
4 ./scf/lib
4 ./scf/service/deploy/product
4 ./scf/service/deploy/info
12 ./scf/service/deploy
16 ./scf/service
4 ./scf/doc
4 ./scf/bin
32 ./scf
8 ./test3
1288 .
[root@localhost test]#
說(shuo)明:
只顯(xian)示(shi)當前目錄下面(mian)的(de)(de)(de)子目錄的(de)(de)(de)目錄大小和(he)當前目錄的(de)(de)(de)總的(de)(de)(de)大小,最下面(mian)的(de)(de)(de)1288為(wei)當前目錄的(de)(de)(de)總大小
實例2:顯示指(zhi)定(ding)文件所占(zhan)空間
命令:
du log2012.log
輸出(chu):
[root@localhost test]# du log2012.log
300 log2012.log
[root@localhost test]#
說明:
實例3:查看指定目錄的(de)所占(zhan)空間(jian)
命令:
du scf
輸出:
[root@localhost test]# du scf
4 scf/lib
4 scf/service/deploy/product
4 scf/service/deploy/info
12 scf/service/deploy
16 scf/service
4 scf/doc
4 scf/bin
32 scf
[root@localhost test]#
說(shuo)明(ming):
實例4:顯示多(duo)個文件所占空間
命令:
du log30.tar.gz log31.tar.gz
輸出:
[root@localhost test]# du log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
[root@localhost test]#
說(shuo)明:
實例5:只顯示總和的(de)大小(xiao)
命令:
du -s
輸出(chu):
[root@localhost test]# du -s
1288 .
[root@localhost test]# du -s scf
32 scf
[root@localhost test]# cd ..
[root@localhost soft]# du -s test
1288 test
[root@localhost soft]#
說(shuo)明:
實(shi)例6:方便閱讀的格式顯示(shi)
命令:
du -h test
輸出:
[root@localhost soft]# du -h test
608K test/test6
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
8.0K test/test3
1.3M test
[root@localhost soft]#
說(shuo)明:
實(shi)例7:文(wen)件和目錄都顯示(shi)
命令:
輸出:
[root@localhost soft]# du -ah test
4.0K test/log31.tar.gz
4.0K test/test13.tar.gz
0 test/linklog.log
0 test/test6/log2014.log
300K test/test6/linklog.log
0 test/test6/log2015.log
4.0K test/test6/log2013.log
300K test/test6/log2012.log
0 test/test6/log2017.log
0 test/test6/log2016.log
608K test/test6
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]#
說明(ming):
實(shi)例8:顯示幾(ji)個文件(jian)或目(mu)錄各自占(zhan)用(yong)磁盤空間的大小,還統(tong)計它們的總和
命令:
du -c log30.tar.gz log31.tar.gz
輸出(chu):
[root@localhost test]# du -c log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
8 總計
[root@localhost test]#
說明:
加上(shang)-c選項后(hou),du不(bu)僅顯示兩個目(mu)錄(lu)各(ge)自占(zhan)用(yong)磁盤空間的(de)大小,還在(zai)最(zui)后(hou)一(yi)行(xing)統計它們的(de)總和。
實例9:按照空(kong)間大小(xiao)排序
命令(ling):
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]#
說(shuo)明:
實例10:輸(shu)出當前目錄下各個(ge)子目錄所使(shi)用的空間
命(ming)令:
du -h --max-depth=1
輸出:
[root@localhost test]# du -h --max-depth=1
608K ./test6
308K ./test4
32K ./scf
8.0K ./test3
1.3M .
[root@localhost test]#
說明:
關注 熵減黑客 ,一起學習成長
