du
文件与目录
用法
du -sh [path]统计文件真正占用的磁盘空间;它按分配的块来算,所以总数和文件大小之和、和 df 都不一样。
常用选项
| 选项 | 含义 |
|---|---|
| -s | One total per argument instead of every subdirectory |
| -h | Readable sizes such as 1.2G |
| -a | Include files, not only directories |
| -d | Limit the depth; GNU also spells it --max-depth |
| -x | Stay on one filesystem |
| -c | Print a grand total at the end |
示例
du -sh *Size of every item in this directory.
du -h -d 1 / | sort -hTop-level directories, smallest to biggest.
du -shx /varSize of /var without crossing into other mounts.
移动、删除和查找。有些命令不会再问一遍,所以顺手加 -i 是在救自己。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. du 是做什么的?
统计文件真正占用的磁盘空间;它按分配的块来算,所以总数和文件大小之和、和 df 都不一样。
Q. 怎么写?
du -sh [path] —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 6 个,完整列表在 man du。这条命令属于文件与目录。
相关命令
man 手册: man du