在 Linux 中查看文件夹大小的常用命令如下:
du
(Disk Usage)命令基本语法:
du -sh /path/to/directory
-s
:显示总大小(不递归显示子目录)-h
:以人类可读格式显示(如 KB、MB、GB)/path/to/directory
:目标目录路径(默认为当前目录)示例:
du -sh /home # 查看 /home 目录的总大小
du -sh . # 查看当前目录大小
扩展用法:
- 查看目录及其子目录的大小:
bash
du -h /path/to/directory
- 按大小排序(配合 sort
):
bash
du -h /path/to/directory | sort -h
- 限制深度(如只显示 1 级子目录):
bash
du -h --max-depth=1 /path/to/directory
ncdu
命令(交互式工具)若需更直观的交互式查看,可安装 ncdu
:
sudo apt install ncdu # Debian/Ubuntu
sudo yum install ncdu # CentOS/RHEL
使用方式:
ncdu /path/to/directory
tree
(显示目录树及大小):
tree -d -h /path/to/directory
(需安装 tree
包)
ls
(仅查看直接文件大小,不递归):
ls -lh
du
可能耗时较长(尤其是大目录)。sudo
(如 sudo du -sh /path
)。--exclude="*.log"
)。根据需求选择合适命令即可!