例如,我有一个很大的文件系统,它的填充速度比我预期的要快。
find /rapidly_shrinking_drive/ -type f -mtime -1 -ls | less
我找到了很多东西,成千上万的六七种类型的文件,我可以挑出一种来数:
find /rapidly_shrinking_drive/ -name "*offender1*" -mtime -1 -ls | wc -l
但我真正希望的是能够获得这些文件在磁盘上的总大小:
find /rapidly_shrinking_drive/ -name "*offender1*" -mtime -1 | howmuchspace
如果有人有Perl一行程序,我愿意使用它,但我不会使用任何涉及多行脚本或File::Find的解决方案。
8条答案
按热度按时间bwntbbo31#
命令
du
会告诉您磁盘使用情况。您的特定情况下的使用示例:(以前我写过
du -hs
,但在我的机器上,它似乎忽略了find
的输入,而是总结了cwd的大小。)aemubtdh2#
该死的,Stephan 202是对的。我没有考虑du -s(总结),所以我用了awk:
不过我更喜欢另一个答案,而且几乎可以肯定它更有效。
vjhs03f73#
有了GNU find,
fgw7neuy4#
我想把jason上面的评论提升到answer的地位,因为我相信它是最容易记忆的(虽然不是最通用的,如果你真的要用
find
指定文件列表的话):ih99xse15#
最近我面临着同样的(几乎)问题,我想出了这个解决方案。
它将以字节为单位显示文件大小,从
man find
:为了得到总数,我用了这个:
dfddblmv6#
我已经尝试了所有这些命令,但没有运气。所以我找到了这个给我一个答案:
vuv7lop37#
既然OP明确地说:
如果有人有Perl一行程序,我愿意使用它,但我不会使用任何涉及多行脚本或File::Find的解决方案。
......而且还没有,下面是perl的一行程序:
这不是
use strict
模式,因此可以省略BEGIN
块中的$t
声明:wh6knrhe8#
您也可以使用
ls -l
来找出它们的大小,然后使用awk
来撷取大小: