linux du(disk usage)与df(disk free),共同点是:
-h
方便人阅读df -h test
或者du -h test
du用法:
du -h --max-depth=1
展示当前目录下各文件夹大小du -sh
展示当前目录大小汇总df用法:
df -h
展示各个目录的占用空间https://www.quora.com/What-is-the-difference-between-DU-and-DF-in-Linux
Basically, df reads the superblock only and trusts it completely. du reads each object and sums them up.
Also, a running process can keep a deleted file open. This means the space will still be reserved and seen by df, but since du will no longer see a reference to that file in the directory tree, it cannot see those reserved blocks.
详细分析du和df的统计结果为什么不一样 总结得出:
du -sh / 2>/dev/null
比df -hT
大是因为df
不会统计挂载目录的大小du
比df
运行慢是因为前者通过对每个文件执行stat命令获取文件大小,后者读取元数据块获取空间大小df
比du
统计比大,可能因为文件删除时仍有进程使用,则对应数据块不是“未使用”状态,该文件对du不可见,但数据块对于df仍然占用。(“df会统计已删除但却仍有进程引用的文件”一节提到)