css - 如何使用shell脚本分别计算所有css、js和html页面的总大小?

标签 css linux bash shell unix

我在shell脚本中有以下代码

find -name "*.css" -exec -printf '%16f Size: %6s\n'

这给了我每个 css 文件的文件大小。我如何修改它以获得所有文件大小的总和?

最佳答案

你可以使用 awk:

find . -name "*.css" -type f -printf '%s\n' | awk '{ tot+=$0 } END { print tot }'

或者在纯 bash 中:

total=0
while read -r s; 
do 
  total=$(( total+s ))
done < <(find . -name "*.css" -type f -printf '%s\n')

echo $total

关于css - 如何使用shell脚本分别计算所有css、js和html页面的总大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28586520/

相关文章:

html - 背景图片未延伸至页面底部

html - 如何在不重新定位的情况下扩展 DIV 以适应设定位置的设定区域?

Mysql返回有错误的记录——聚合函数MAX()

linux - 安装 Docker 时出错 - curl : (23) Failed writing body (0 ! = 13847)

c - 使用 POSIX 系统函数在 C 中实现 rev 命令

linux - 奇怪的 "sh"行为

javascript - 链接到新 HTML 页面中的某个部分

css - 上升和下降按钮是如何制作的?

linux - 用于基本数学运算的 Bash 脚本

bash - 如何用find和sed生成随机数?