每天一個linux命令(34):du 命令
Linux du命令也是檢視使用空間的,但是與df命令不同的是Linux du命令是對檔案和目錄磁碟使用的空間的檢視,還是和df命令有一些區別的.
1.命令格式:
du [選項][檔案]
2.命令功能:
顯示每個檔案和目錄的磁碟使用空間。
3.命令引數:
-a或-all 顯示目錄中個別檔案的大小。
-b或-bytes 顯示目錄或檔案大小時,以byte為單位。
-c或--total 除了顯示個別目錄或檔案的大小外,同時也顯示所有目錄或檔案的總和。
-k或--kilobytes 以KB(1024bytes)為單位輸出。
-m或--megabytes 以MB為單位輸出。
-s或--summarize 僅顯示總計,只列出最後加總的值。
-h或--human-readable 以K,M,G為單位,提高資訊的可讀性。
-x或--one-file-xystem 以一開始處理時的檔案系統為準,若遇上其它不同的檔案系統目錄則略過。
-L或--dereference 顯示選項中所指定符號連結的原始檔大小。
-S或--separate-dirs 顯示個別目錄的大小時,並不含其子目錄的大小。
-X或--exclude-from= 在指定目錄或檔案。
--exclude= 略過指定的目錄或檔案。
-D或--dereference-args 顯示指定符號連結的原始檔大小。
-H或--si 與-h引數相同,但是K,M,G是以1000為換算單位。
-l或--count-links 重複計算硬體連結的檔案。
4.使用例項:
例項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]#
說明:
只顯示當前目錄下面的子目錄的目錄大小和當前目錄的總的大小,最下面的1288為當前目錄的總大小
例項2:顯示指定檔案所佔空間
命令:
du log2012.log
輸出:
[root@localhost test]# du log2012.log
300 log2012.log
[root@localhost test]#
說明:
例項3:檢視指定目錄的所佔空間
命令:
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]#
說明:
例項4:顯示多個檔案所佔空間
命令:
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]#
說明:
例項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]#
說明:
例項6:方便閱讀的格式顯示
命令:
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]#
說明:
例項7:檔案和目錄都顯示
命令:
輸出:
[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]#
說明:
例項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 .
[root@localhost test]#
說明:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29119536/viewspace-1121139/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 每天一個 Linux 命令(34): du 命令Linux
- 每天一個Linux命令-使用du檢視檔案大小Linux
- 每天一個 Linux 命令(49): at 命令Linux
- 每天一個linux命令(49):at命令Linux
- linux命令 之 du 命令Linux
- 每天一個 Linux 命令(12):more 命令Linux
- 每天一個 Linux 命令(16):which 命令Linux
- 每天一個Linux命令(6):rmdir命令Linux
- 每天一個Linux命令(5):rm命令Linux
- 每天一個Linux命令(2):shutdown命令Linux
- 每天一個 Linux 命令(17):whereis 命令Linux
- 每天一個Linux命令(3):pwd命令Linux
- 每天一個 Linux 命令(2):cd命令Linux
- 每天一個linux命令(1):ls命令Linux
- 每天一個 Linux 命令(16):which命令Linux
- 每天一個 Linux 命令(18):locate 命令Linux
- 每天一個 Linux 命令(7):mv命令Linux
- 每天一個 Linux 命令(4):mkdir命令Linux
- 每天一個 Linux 命令(28):tar 命令Linux
- 每天一個 Linux 命令(44): top 命令Linux
- 每天一個 Linux 命令(41): ps 命令Linux
- 每天一個 Linux 命令(40): wc 命令Linux
- 每天一個 Linux 命令(48): watch 命令Linux
- 每天一個 Linux 命令(46): vmstat 命令Linux
- 每天一個 Linux 命令(45): free 命令Linux
- 每天一個 Linux 命令(1):ls 命令Linux
- 每天一個 Linux 命令(2):cd 命令Linux
- 每天一個 Linux 命令(3):pwd 命令Linux
- 每天一個 Linux 命令(37): date 命令Linux
- 每天一個 Linux 命令(36): diff 命令Linux
- 每天一個 Linux 命令(35): ln 命令Linux
- 每天一個 Linux 命令(33):df 命令Linux
- 每天一個 Linux 命令(32):gzip 命令Linux
- 每天一個 Linux 命令(30): chown 命令Linux
- 每天一個 Linux 命令(60): scp命令Linux
- 每天一個 Linux 命令(59): rcp 命令Linux
- 每天一個 Linux 命令(57): ss 命令Linux
- 每天一個 Linux 命令(53): route 命令Linux