Skip to content
Joey Wang
Menu

Search

DevOps and Reliability

count file size from json

A bash one-liner that uses jq to pull resource IDs out of lesson JSON files, then du to total their file sizes on disk.

· 1 min read

devops #bash#jq#automation

Audio summary
set -o nounset                              # Treat unset variables as an error

for f in ../json/lesson_[0-9]*.json
#for f in ../json/lesson_1608905.json
do
  lesson_id=${f:15:7}
  out=`jq '..|select(objects and has("resourceType") and (.resourceType|length>0)).resourceID' $f|xargs du -chk ../activity/*|tail -n 1 |awk -F ' ' '{print ($1-501)}'`
  echo "$lesson_id ${out}K"
done