查找与通配符匹配的文件总大小的简短命令 [英] Short command to find total size of files matching a wild card

查看:82
本文介绍了查找与通配符匹配的文件总大小的简短命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以设想一个简单的shell脚本,只需遍历目录中的文件列表并累加各个大小即可实现我想要的功能,但是想知道是否已经有一种更简洁的方法了.

I could envision a simple shell script that would accomplish what I want by just iterating through a list of files in a directory and summing the individual size but was wondering if there was already a more concise way to do that.

类似

ls -lh *.jpg

这给了我目录中所有jpg文件的总大小

that gives me the total size of just all the jpg files in the directory

推荐答案

尝试 du 总结磁盘使用情况:

Try du to summarize disk usage:

du -csh *.jpg

输出(例如):

8.0K sane-logo.jpg
16K sane-umax-advanced.jpg
28K sane-umax-histogram.jpg
24K sane-umax.jpg
16K sane-umax-standard.jpg
4.0K sane-umax-text2.jpg
4.0K sane-umax-text4.jpg
4.0K sane-umax-text.jpg
104K total

du 不总结文件的大小,而是总结文件系统中使用的块的大小.如果文件的大小为13K,而文件系统使用的块大小为4K,则该文件将显示为16K.

du does not summarize the size of the files but summarizes the size of the used blocks in the file system. If a file has a size of 13K and the file system uses a block size of 4K, then 16K is shown for this file.

这篇关于查找与通配符匹配的文件总大小的简短命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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