du
命令用以檢視檔案和目錄的大小。可以方便地檢視每個檔案和目錄所佔用的空間。
基本語法
du [options][file]
複製程式碼
可使用的options值可以通過 man df
命令查閱,這裡不再贅述。
例項
顯示目錄或者檔案所佔空間:
du /opt/log/*
複製程式碼
我們可以看到log目錄下所有的檔案大小:
20 /opt/log/project/houtai/pc/suyun/log4js/2018-09-28
12 /opt/log/project/houtai/pc/suyun/log4js/2018-06-28
12 /opt/log/project/houtai/pc/suyun/log4js/2018-08-26
16 /opt/log/project/houtai/pc/suyun/log4js/2018-10-27
12 /opt/log/project/houtai/pc/suyun/log4js/2018-07-01
16 /opt/log/project/houtai/pc/suyun/log4js/2018-08-23
20 /opt/log/project/houtai/pc/suyun/log4js/2018-10-22
複製程式碼
通過使用-h
讓輸出的檔案大小可讀性更好一些:
du -h /opt/log/*
複製程式碼
可以看到檔案大小新增了單位K:
20 /opt/log/project/houtai/pc/suyun/log4js/2018-09-28
12 /opt/log/project/houtai/pc/suyun/log4js/2018-06-28
12 /opt/log/project/houtai/pc/suyun/log4js/2018-08-26
16 /opt/log/project/houtai/pc/suyun/log4js/2018-10-27
12 /opt/log/project/houtai/pc/suyun/log4js/2018-07-01
16 /opt/log/project/houtai/pc/suyun/log4js/2018-08-23
20 /opt/log/project/houtai/pc/suyun/log4js/2018-10-22
複製程式碼
只展示總計大小:
du -sh /opt/log/*
複製程式碼
只統計了log目錄下子目錄的大小,而沒有細化到具體的檔案。
0 /opt/log/:
12G /opt/log/banjia
4.0K /opt/log/driver-manage
2.1G /opt/log/fe-sy-banjia
8.7G /opt/log/fe-sy-lahuo
539M /opt/log/lahuo
32K /opt/log/lahuo-work
16G /opt/log/nginx
157G /opt/log/project
248K /opt/log/sale-manage
100K /opt/log/youpei
複製程式碼