某門戶網站突發故障,控制台報日誌寫入錯誤。初步懷疑磁碟損壞觸發唯讀掛載,經機房確認硬體無告警,轉向軟體層面排查。
df -h
# 發現 /dev/mapper/vg-root 使用率 100%

# 只統計第一層目錄大小,以人類可讀單位顯示
du -h --max-depth=1 / | sort -hr
# 輸出範例
7.8G /weblogic
1.2G /var
500M /usr
...

關鍵參數:
-h:人類可讀單位 (K/M/G)
--max-depth=1:只顯示第一層,避免遞迴耗時
sort -hr:人類單位反向排序,大戶浮上來
cd /weblogic
du -h --max-depth=1 . | sort -hr
# 發現三個 .log 檔案各逼近 2.5GB,共佔 7.8GB

truncate -s 0 access.log error.log out.log 清空日誌 (不重啟服務),並要求廠商恢復清理機制。logrotate (按大小/時間輪轉、壓縮、保留份數)。# 找出全系統 > 100MB 的檔案
find / -type f -size +100M -exec ls -lh {} \;
# 找出 /var/log 下 > 50MB 的檔案
find /var/log -type f -size +50M -ls
# ncdu (NCurses Disk Usage) 互動式視覺化工具,強烈推薦
yum install -y ncdu
ncdu /