Linux常用命令(二十八)-du

來源:互聯網
上載者:User

Linux常用命令(二十八)-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.命令執行個體:

執行個體一. 顯示目錄或檔案所佔空間

命令:du

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

 

[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    .[root@localhost test]#

執行個體二. 顯示指定檔案所佔空間

 

命令:du log2012.log

 

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

執行個體三. 查看指定目錄的所佔空間

 

命令: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]#

 

 

執行個體四. 顯示多個檔案所佔空間

命令: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]#

執行個體五. 只顯示總和的大小

 

命令: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]#

 

 

執行個體六. 以方便閱讀的格式顯示

命令: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]#

執行個體七. 檔案和目錄都顯示

 

命令:du -ah test

 

[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]#

執行個體八. 顯示幾個檔案或目錄各自佔用磁碟空間的大小,並統計它們的總和

 

命令: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]#

 

 

執行個體九. 按照空間大小排序

命令: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]#

 

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

命令: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.