Bash:当前目录中匹配正则表达式的文件总大小 [英] Bash: total size of file in current directory matching regular expression

查看:29
本文介绍了Bash:当前目录中匹配正则表达式的文件总大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ls | grep -P "$1" | awk '{ x += $5 } END { print "total bytes:" x }' 

这段代码使用[0-9]"作为reg expr返回0,在当前文件夹中有2个文件名为:1"和6",每个文件的大小为138字节.

This code is returning 0 using "[0-9]" as reg expr, in current folder there are 2 files named: "1" and "6", each one with size of 138bytes.

谁能帮我找出问题所在?

Anyone could help me to find the problem?

推荐答案

您只是缺少 ls-l 选项.

You're just missing the -l option to ls.

ls -l | grep -P "$1" | awk '{ x += $5 } END { print "total bytes:" x }' 

这篇关于Bash:当前目录中匹配正则表达式的文件总大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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