【轉】每天一個linux命令(34):du 命令

來源:互聯網
上載者:User

標籤:

原文網址:http://www.cnblogs.com/peida/archive/2012/12/10/2810755.html

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

輸出:

[[email protected] 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    .

[[email protected] test]#

 

說明:

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

 

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

命令:

du log2012.log

輸出:

[[email protected] test]# du log2012.log 

300     log2012.log

[[email protected] test]#

說明:

 

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

命令:

du scf

輸出:

[[email protected] 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

[[email protected] test]#

說明:

 

執行個體4:顯示多個檔案所佔空間

命令:

du log30.tar.gz log31.tar.gz

輸出:

[[email protected] test]# du log30.tar.gz log31.tar.gz 

4       log30.tar.gz

4       log31.tar.gz

[[email protected] test]#

說明:

 

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

命令:

du -s

輸出:

[[email protected] test]# du -s

1288    .

[[email protected] test]# du -s scf

32      scf

[[email protected] test]# cd ..

[[email protected] soft]# du -s test

1288    test

[[email protected] soft]#

說明:

 

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

命令:

du -h test

輸出:

[[email protected] 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

[[email protected] soft]#

 

說明:

 

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

命令:

輸出:

[[email protected] 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

[[email protected] soft]#

說明:

 

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

命令:

du -c log30.tar.gz log31.tar.gz

輸出:

[[email protected] test]# du -c log30.tar.gz log31.tar.gz 

4       log30.tar.gz

4       log31.tar.gz

8       總計

[[email protected] test]#

 

說明:

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

 

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

命令:

du|sort -nr|more

輸出:

[[email protected] 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

[[email protected] test]#

 

說明:

 

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

命令:

du -h  --max-depth=1

輸出:

[[email protected] test]# du -h  --max-depth=1

608K    ./test6

308K    ./test4

32K     ./scf

8.0K    ./test3

1.3M    .

[[email protected] test]#

說明:

【轉】每天一個linux命令(34):du 命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.