Linux磁盤管理之df命令詳細(xì)介紹和使用實(shí)例(統(tǒng)計(jì)文件或目錄的磁盤占用情況)
1.命令格式:
du[選項(xiàng)][文件]
2.命令功能:
顯示每個(gè)文件和目錄的磁盤使用空間。
3.命令參數(shù):
-a或-all顯示目錄中個(gè)別文件的大小。
-b或-bytes顯示目錄或文件大小時(shí),以byte為單位。
-c或--total除了顯示個(gè)別目錄或文件的大小外,同時(shí)也顯示所有目錄或文件的總和。
-k或--kilobytes以KB(1024bytes)為單位輸出。
-m或--megabytes以MB為單位輸出。
-s或--summarize僅顯示總計(jì),只列出最后加總的值。
-h或--human-readable以K,M,G為單位,提高信息的可讀性。
-x或--one-file-xystem以一開始處理時(shí)的文件系統(tǒng)為準(zhǔn),若遇上其它不同的文件系統(tǒng)目錄則略過(guò)。
-L<符號(hào)鏈接>或--dereference<符號(hào)鏈接>顯示選項(xiàng)中所指定符號(hào)鏈接的源文件大小。
-S或--separate-dirs顯示個(gè)別目錄的大小時(shí),并不含其子目錄的大小。
-X<文件>或--exclude-from=<文件>在<文件>指定目錄或文件。
--exclude=<目錄或文件>略過(guò)指定的目錄或文件。
-D或--dereference-args顯示指定符號(hào)鏈接的源文件大小。
-H或--si與-h參數(shù)相同,但是K,M,G是以1000為換算單位。
-l或--count-links重復(fù)計(jì)算硬件鏈接的文件。
4.使用實(shí)例:
實(shí)例1:顯示目錄或者文件所占空間
命令: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]#
說(shuō)明:
只顯示當(dāng)前目錄下面的子目錄的目錄大小和當(dāng)前目錄的總的大小,最下面的1288為當(dāng)前目錄的總大小
實(shí)例2:顯示指定文件所占空間
命令:dulog2012.log
輸出:
[root@localhost test]# du log2012.log
300 log2012.log
[root@localhost test]#
實(shí)例3:查看指定目錄的所占空間
命令:duscf
輸出:
[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]#
實(shí)例4:顯示多個(gè)文件所占空間
命令:dulog30.tar.gzlog31.tar.gz
輸出:
[root@localhost test]# du log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
[root@localhost test]#
實(shí)例5:只顯示總和的大小
命令:du-s
輸出:
[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]#
實(shí)例6:方便閱讀的格式顯示
命令:du-htest
輸出:
[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]#
實(shí)例7:文件和目錄都顯示
命令:du-ahtest
輸出:
[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]#
實(shí)例8:顯示幾個(gè)文件或目錄各自占用磁盤空間的大小,還統(tǒng)計(jì)它們的總和
命令:du-clog30.tar.gzlog31.tar.gz
輸出:
[root@localhost test]# du -c log30.tar.gz log31.tar.gz
4 log30.tar.gz
4 log31.tar.gz
8 總計(jì)
[root@localhost test]#
加上-c選項(xiàng)后,du不僅顯示兩個(gè)目錄各自占用磁盤空間的大小,還在最后一行統(tǒng)計(jì)它們的總和。
實(shí)例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]#
實(shí)例10:輸出當(dāng)前目錄下各個(gè)子目錄所使用的空間
命令: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]#
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。