如何在Linux中仅递归地计算某些文件的总大小 [英] How to calculate the total size of certain files only, recursive, in linux

查看:143
本文介绍了如何在Linux中仅递归地计算某些文件的总大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆文件分散在布局中的各个文件夹中,例如:

I've got a bunch of files scattered across folders in a layout, e.g.:

dir1/somefile.gif
dir1/another.mp4
dir2/video/filename.mp4
dir2/some.file
dir2/blahblah.mp4

我需要找到仅用于 的MP4文件的总磁盘空间.这意味着它必须以某种方式递归.

And I need to find the total disk space used for the MP4 files only. This means it's gotta be recursive somehow.

我已经看过du并摸索到grep的东西,但无论如何,似乎都无法弄清楚如何仅计算MP4文件.

I've looked at du and fiddling with piping things to grep but can't seem to figure out how to calculate just the MP4 files no matter where they are.

必须人工输出总磁盘空间,如果可能的话,最好以GB为单位?

A human readable total disk space output is a must too, preferably in GB, if possible?

有什么想法吗?谢谢

推荐答案

对于单个文件大小:

find . -name "*.mp4" -print0 | du -sh --files0-from=- 

以GB为单位的磁盘总空间:

For total disk space in GB:

find . -name "*.mp4" -print0 | du -sb --files0-from=-  | awk '{ total += $1} END { print total/1024/1024/1024 }'

这篇关于如何在Linux中仅递归地计算某些文件的总大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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