我在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/