使用“查找"选择的文件组的总大小 [英] total size of group of files selected with 'find'

查看:17
本文介绍了使用“查找"选择的文件组的总大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个大型文件系统,它的填充速度比我预期的要快.所以我寻找正在添加的内容:

For instance, I have a large filesystem that is filling up faster than I expected. So I look for what's being added:

find /rapidly_shrinking_drive/ -type f -mtime -1 -ls | less

而且我发现了很多东西.数以千计的六七种文件.我可以挑出一个类型并计算它们:

And I find, well, lots of stuff. Thousands of files of six-seven types. I can single out a type and count them:

find /rapidly_shrinking_drive/ -name "*offender1*" -mtime -1 -ls | wc -l

但我真正想要的是能够获得这些文件在磁盘上的总大小:

but what I'd really like is to be able to get the total size on disk of these files:

find /rapidly_shrinking_drive/ -name "*offender1*" -mtime -1 | howmuchspace

我愿意为此使用 Perl 单行,如果有人有的话,但我不会使用任何涉及多行脚本或 File::Find 的解决方案.

I'm open to a Perl one-liner for this, if someone's got one, but I'm not going to use any solution that involves a multi-line script, or File::Find.

推荐答案

命令 du 告诉你磁盘使用情况.您的特定情况的示例用法:

The command du tells you about disk usage. Example usage for your specific case:

find rapidly_shrinking_drive/ -name "offender1" -mtime -1 -print0 | du --files0-from=- -hc | tail -n1

(之前我写了 du -hs,但在我的机器上似乎忽略了 find 的输入,而是总结了 cwd 的大小.)

(Previously I wrote du -hs, but on my machine that appears to disregard find's input and instead summarises the size of the cwd.)

这篇关于使用“查找"选择的文件组的总大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆