计算 bash 上的磁盘使用情况。已使用的大于 space 的文件总数,

Calculate disk usage on bash. sum of files bigger than space used,

我正在尝试计算过去 365 天内创建的文件使用的大小

使用此答案提供的信息 calculate total used disk space by files older than 180 days using find

find . -type f -mtime -1 -printf '%s\n' | awk '{total=total+}END{print total/1024}'

应该可以,但是结果不符合预期,结果比文件夹大。

所以我只用一个文件夹做了一个简单的测试,没有按日期筛选。

[log]$ du
601407  .
[log]$ find . -type f -printf '%s\n' | awk '{total=total+}END{print total/1024}'
720779

DU的结果大于单个文件的SUM。 为什么?

我的文件夹在几个子文件夹中包含数千个小于 10 KB 的文件。与某些最小簇大小有关吗?

正在使用

du --apparent-size

按照@matias-barrios 和@barmar 的指示解决我的问题

更多信息请见https://superuser.com/questions/94217/why-ls-and-du-show-different-size