詳細分析Linux du命令的使用

來源:互聯網
上載者:User

Linux du命令也是查看使用空間的,但是與df命令不同的是Linux du命令是對檔案和目錄磁碟使用的空間的查看,還是和df命令有一些區別的,這裡介紹Linux du命令。

du:查詢檔案或目錄的磁碟使用空間
a:顯示全部目錄和其次目錄下的每個檔案所佔的磁碟空間
b:大小用bytes來表示 (預設值為k bytes)
c:最後再加上總計 (預設值)
s:只顯示各檔案大小的總合
x:只計算同屬同一個檔案系統的檔案
L:計算所有的檔案大小

常用命令:du –a
操作詳解
引用
指令 du 能以指定的目錄下的子目錄為單位,顯示每個目錄內所有檔案所佔用的磁碟空間大小。例如:
# du -h /etc
104K /etc/defaults
6.0K /etc/X11
8.0K /etc/bluetooth
4.0K /etc/gnats
52K /etc/isdn
388K /etc/mail
68K /etc/mtree
2.0K /etc/ntp
38K /etc/pam.d
44K /etc/periodic/daily
6.0K /etc/periodic/monthly
42K /etc/periodic/security
16K /etc/periodic/weekly
110K /etc/periodic
6.0K /etc/ppp
318K /etc/rc.d
2.0K /etc/skel
130K /etc/ssh
10K /etc/ssl
1.7M /etc
我們目樣使用 -h 參數來顯示 human-readable 的格式。在應用時,我們可以使用 du 這個指令來查看哪個目錄佔用最多的空間。不過,du 的輸出結果通常很長,我們可以加上 -s 參數來省略指定目錄下的子目錄,而只顯示該目錄的總合即可:
# du -sh /etc
1.7M /etc
在查看目錄的使用情形時,我們可以將輸出結果導到 sort 指令進行排序,以瞭解哪個檔案用了最多的空間:
# du /etc | sort -nr | more
1746 /etc
388 /etc/mail
318 /etc/rc.d
130 /etc/ssh
110 /etc/periodic
104 /etc/defaults
68 /etc/mtree
52 /etc/isdn
44 /etc/periodic/daily
42 /etc/periodic/security
38 /etc/pam.d
16 /etc/periodic/weekly
10 /etc/ssl
8 /etc/bluetooth
6 /etc/ppp
6 /etc/periodic/monthly
6 /etc/X11
4 /etc/gnats
2 /etc/skel
2 /etc/ntp
sort 的參數 -nr 表示要以數字排序法進行反向排序,因為我們要對目錄大小做排序,所以不可以使用 human-readable 的大小輸出,不然目錄大小中會有 K、M 等字樣,會造成排序不正確。

現在明了了Linux du命令和Linux df命令的不同之處了嗎。

  1. 詳細分析Linux df命令的使用方法
  2. 解析Linux NTFS分區的應用
  3. 深入分析Linux分區基礎
  4. 綜述Linux Unix區別
  5. 詳細剖析Linux防火牆配置


聯繫我們

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