每天一個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命令-使用du檢視檔案大小Linux
- 每天一個Linux命令(6):rmdir命令Linux
- 每天一個Linux命令(5):rm命令Linux
- 每天一個Linux命令(2):shutdown命令Linux
- 每天一個 Linux 命令(12):more 命令Linux
- 每天一個 Linux 命令(16):which 命令Linux
- Linux基礎命令---duLinux
- 每天一個linux命令(1):find命令之execLinux
- 每天一個Linux命令(1):xargsLinux
- 每天學一個 Linux 命令(15):manLinux
- 每天學一個 Linux 命令(13):touchLinux
- linux 命令之du與dfLinux
- 每天學習一個Linux命令-目錄Linux
- 每天一個linux命令--持續更新中~~Linux
- du 命令秘籍
- LINUX磁碟使用命令DU的改進Linux
- Linux 基礎教程 40-df和du命令Linux
- 學習一個 Linux 命令:shutdown 命令Linux
- Linux檔案系統df、du、fsck命令講解Linux
- 如何使用du 和 ncdu 兩個命令檢查 Linux 磁碟使用情況?Linux
- 每天一個設計模式之命令模式設計模式
- 每天一個Linux命令之ps-檢視系統程式資訊Linux
- 『學了就忘』Linux基礎命令 — 34、配置網路相關命令Linux
- 學習一個 Linux 命令:pstreeLinux
- 每天一條Linux命令(24) ssh (遠端安全登入)Linux
- du 及 df 命令的使用(附帶示例)
- linux最常用的20個命令(一)Linux
- 【Linux命令】grep命令Linux
- Linux命令—–CP命令Linux
- Linux簡單命令(一)Linux
- linux刪除資料夾命令是什麼 linux刪除一個目錄的命令Linux
- 6個有趣的Linux命令Linux
- Linux命令技巧之30個必會的命令技巧Linux
- 重新點亮linux 命令樹————幫助命令[一]Linux
- Linux的幾個新手必備的命令(一)Linux
- 如何用Linux的at命令安排一個任務Linux
- Linux命令(1)——xargs命令Linux
- Linux命令之lldptool命令Linux
- Linux命令篇 - sed 命令Linux