Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 目錄大小快速查詢:du 指令參數與實戰範例

編輯:Linux 教學

核心指令


du -sh /path/to/dir
# -s: 只顯示總計 (summary)
# -h: 人類可讀單位 (K, M, G)

常用變體

指令用途
du -sh /home查看 /home 總大小
du -h --max-depth=1 /home顯示 /home 下一層子目錄大小
du -ah /var/log | sort -hr | head -20找出 /var/log 前 20 大檔案/目錄
du -sh * | sort -hr當前目錄下所有項目按大小排序
du -sh /home/* 2>/dev/null | grep '[0-9]G'找出超過 1G 的用戶目錄

Apache 快取清理範例 (原文片段)


/usr/local/apache/bin/htcacheclean -v -p /cacheroot -l 500M
Statistics:
size limit 500.0M
total size was 91.8M, total size now 91.8M
total entries was 3754, total entries now 3754

進階:排除掛載點 / 跨檔案系統


du -sh -x /        # -x 僅統計當前檔案系統,不跨掛載點
du -sh --exclude=/mnt/backup /data

總結

du -sh 是「目錄佔用多少空間」的標準答案。搭配 --max-depth、sort、grep 即可快速定位大目錄/大檔案,指導清理決策。

Copyright © Windows教程網 All Rights Reserved