在Linux系统中,有几种常用方法可以查看目录下文件的大小:
ls
命令ls -lh
-l
显示详细信息-h
以人类可读的格式显示大小(KB, MB, GB)du
命令(disk usage)du -sh *
-s
显示总计大小-h
人类可读格式*
表示当前目录下所有文件和目录查看特定目录:
du -sh /path/to/directory
ls -lhS
-S
按文件大小排序(从大到小)或者更详细的排序:
ls -lSh --time=ctime
ncdu
工具(需要安装)这是一个交互式磁盘使用分析器:
ncdu /path/to/directory
安装方法:
sudo apt install ncdu # Debian/Ubuntu
sudo yum install ncdu # CentOS/RHEL
ls -lah
du -sh .[!.]* *
find /path/to/directory -type f -size +100M -exec ls -lh {} \;
这会查找大于100MB的文件并显示详细信息
du
可能需要一些时间来计算大小-h
参数可以使输出更易读sudo
权限才能查看所有文件选择哪种方法取决于你的具体需求,简单查看用 ls -lh
,详细分析用 du
或 ncdu
。