使用“查找”选择的文件组的总大小;
例如,我有一个大型文件系统,其填充速度比我预期的要快。 所以我寻找正在添加的内容:
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 的解决方案。
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
命令
du
告诉您有关磁盘使用情况的信息。 针对您的具体情况的示例用法:(之前我编写了
du -hs
,但在我的机器上,它似乎忽略了find
的输入,而是总结了 cwd 的大小。 )The command
du
tells you about disk usage. Example usage for your specific case:(Previously I wrote
du -hs
, but on my machine that appears to disregardfind
's input and instead summarises the size of the cwd.)该死,Stephan202 是对的。 我没有考虑 du -s (总结),所以我使用了 awk:
不过我更喜欢另一个答案,而且它几乎肯定更有效。
Darn, Stephan202 is right. I didn't think about du -s (summarize), so instead I used awk:
I like the other answer better though, and it's almost certainly more efficient.
通过 GNU 查找,
with GNU find,
我想将上面杰森的评论提升为答案的状态,因为我相信它是最容易记忆的(虽然不是最通用的,如果你真的需要
find
指定的文件列表):I'd like to promote jason's comment above to the status of answer, because I believe it's the most mnemonic (though not the most generic, if you really gotta have the file list specified by
find
):最近我遇到了同样的(几乎)问题,我想出了这个解决方案。
它将显示文件大小(以字节为单位),来自
man find
:为了获得总数,我使用了以下内容:
Recently i faced the same(almost) problem and i came up with this solution.
It'll show files sizes in bytes, from
man find
:And to get a total i used this:
由于OP明确表示:
...还没有,这是 perl 一行:
Since OP specifically said:
...and there's none yet, here is the perl one-liner:
我已经尝试了所有这些命令,但没有运气。
所以我找到了这个给我答案的:
I have tried all this commands but no luck.
So I have found this one that gives me an answer:
您还可以使用 ls -l 来查找它们的大小,然后使用 awk 来提取大小:
You could also use
ls -l
to find their size, thenawk
to extract the size: