Linux命令教程:du命令 查看磁碟空間

來源:互聯網
上載者:User

Linux命令教程:du命令 查看磁碟空間
du命令,即disk usage,可以計算檔案或目錄所佔的磁碟空間。命令格式:

du [選項][檔案]
du [OPTION]… [FILE]…

沒有指定任何選項時,它會測量當前工作目錄與其所有子目錄,分別顯示各個目錄所佔的空間,最後顯示工作目錄所佔總空間。命令選項:

-a, –all
包括了所有的檔案,而不只是目錄
-B, –block-size=SIZE use SIZE-byte blocks
-b, –bytes 以位元組為計算單位
-k, 以KB(KB)為計算單位
-m, 以MB(M)為計算單位
-c, –total 最後加上一個總計(系統預設)
-D, –dereference-args
dereference FILEs that are symbolic links
-H 跟 - -si效果一樣。
-h, –human-readable 以比較閱讀的方式輸出檔案大小資訊 (例如,1K 234M 2G)。註:該選項在很多其他命令(df, ls)中也有效。
–si 跟-h 效果一樣,只是以1000為換算單位
-l, –count-links 計算所有的檔案大小,對永久連結檔案,則計算多次。
-L, –dereference 顯示選項中所指定符號串連的源檔案大小。
-P, –no-dereference 不跟隨任何的符號串連(預設)
-S, –separate-dirs 計算目錄所佔空間時不包括子目錄的大小。
-s, –summarize 只顯示工作目錄所佔總空間
-x, –one-file-system 以一開始處理時的檔案系統為準,若遇上其它不同的檔案系統目錄則略過。
-X FILE, –exclude-from=FILE 排除掉指定的FILE
–exclude=PATTERN 排除掉符合樣式的檔案,Pattern就是普通的Shell樣式,?表示任何一個字元,*表示任意多個字元。
–max-depth=N
只列出深度小於max-depth的目錄和檔案的資訊 –max-depth=0 的時候效果跟–s是 一樣

使用執行個體:

執行個體1:顯示目錄或者檔案所佔空間 

命令:

du

輸出:

[root@localhost test]# du608     ./test6308     ./test44       ./scf/lib4       ./scf/service/deploy/product4       ./scf/service/deploy/info12      ./scf/service/deploy16      ./scf/service4       ./scf/doc4       ./scf/bin32      ./scf8       ./test31288    .

說明:

只顯示目前的目錄下面的子目錄的目錄大小和目前的目錄的總的大小,最下面的1288為目前的目錄的總大小

執行個體2:顯示指定檔案所佔空間

命令:

du log2012.log

輸出:

[root@localhost test]# du log2012.log 300     log2012.log[root@localhost test]#

執行個體3:查看指定目錄的所佔空間

命令:

du scf

輸出:

[root@localhost test]# du scf4       scf/lib4       scf/service/deploy/product4       scf/service/deploy/info12      scf/service/deploy16      scf/service4       scf/doc4       scf/bin32      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.gz4       log31.tar.gz[root@localhost test]#

執行個體5:只顯示總和的大小

命令:

du -s

輸出:

[root@localhost test]# du -s1288    .[root@localhost test]# du -s scf32      scf[root@localhost test]# cd ..[root@localhost soft]# du -s test1288    test[root@localhost soft]# 

執行個體6:方便閱讀的格式顯示

命令:

du -h test

輸出:

[root@localhost soft]# du -h test608K    test/test6308K    test/test44.0K    test/scf/lib4.0K    test/scf/service/deploy/product4.0K    test/scf/service/deploy/info12K     test/scf/service/deploy16K     test/scf/service4.0K    test/scf/doc4.0K    test/scf/bin32K     test/scf8.0K    test/test31.3M    test[root@localhost soft]# 

執行個體7:檔案和目錄都顯示

命令:

輸出:

[root@localhost soft]# du -ah test4.0K    test/log31.tar.gz4.0K    test/test13.tar.gz0       test/linklog.log0       test/test6/log2014.log300K    test/test6/linklog.log0       test/test6/log2015.log4.0K    test/test6/log2013.log300K    test/test6/log2012.log0       test/test6/log2017.log0       test/test6/log2016.log608K    test/test60       test/log2015.log0       test/test4/log2014.log4.0K    test/test4/log2013.log300K    test/test4/log2012.log308K    test/test44.0K    test/scf/lib4.0K    test/scf/service/deploy/product4.0K    test/scf/service/deploy/info12K     test/scf/service/deploy16K     test/scf/service4.0K    test/scf/doc4.0K    test/scf/bin32K     test/scf4.0K    test/log2013.log300K    test/log2012.log0       test/log2017.log0       test/log2016.log4.0K    test/log30.tar.gz4.0K    test/log.tar.bz24.0K    test/log.tar.gz0       test/test3/log2014.log4.0K    test/test3/log2013.log8.0K    test/test34.0K    test/scf.tar.gz1.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.gz4       log31.tar.gz8       總計[root@localhost test]#

說明:

加上-c選項後,du不僅顯示兩個目錄各自佔用磁碟空間的大小,還在最後一行統計它們的總和。

執行個體9:按照空間大小排序

命令:

du|sort -nr|more

輸出:

[root@localhost test]# du|sort -nr|more1288    .608     ./test6308     ./test432      ./scf16      ./scf/service12      ./scf/service/deploy8       ./test34       ./scf/service/deploy/product4       ./scf/service/deploy/info4       ./scf/lib4       ./scf/doc4       ./scf/bin[root@localhost test]# 

執行個體10:輸出目前的目錄下各個子目錄所使用的空間

命令:

du -h  --max-depth=1

輸出:

[root@localhost test]# du -h  --max-depth=1608K    ./test6308K    ./test432K     ./scf8.0K    ./test31.3M    .[root@localhost test]#

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.