使用find计算超过180天的文件使用的总磁盘空间 [英] calculate total used disk space by files older than 180 days using find
问题描述
我正在尝试查找特定目录中超过180天的文件使用的总磁盘空间.这就是我正在使用的:
I am trying to find the total disk space used by files older than 180 days in a particular directory. This is what I'm using:
find . -mtime +180 -exec du -sh {} \;
但是上面的内容显然是安静的,这给了我找到的每个文件所使用的磁盘空间.我只想要文件使用的总添加磁盘空间.可以使用find
和exec
命令吗?
but the above is quiet evidently giving me disk space used by every file that is found. I want only the total added disk space used by the files. Can this be done using find
and exec
command ?
请注意,我只是不想为此使用脚本,如果可以为此使用一个衬垫,那将是很好的.任何帮助都将受到高度赞赏.
Please note I simply don't want to use a script for this, it will be great if there could be a one liner for this. Any help is highly appreciated.
推荐答案
@PeterT是正确的.几乎所有这些答案都会为每个文件调用一个命令(du),这非常耗费资源,而且速度慢且不必要.最简单,最快的方法是这样:
@PeterT is right. Almost all these answers invoke a command (du) for each file, which is very resource intensive and slow and unnecessary. The simplest and fastest way is this:
find . -type f -mtime +356 -printf '%s\n' | awk '{total=total+$1}END{print total/1024}'
这篇关于使用find计算超过180天的文件使用的总磁盘空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!