Skip to content

Instantly share code, notes, and snippets.

@flavono123
Created August 3, 2022 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flavono123/a1594f3209937f0a8c45a834e5e7dec9 to your computer and use it in GitHub Desktop.
Save flavono123/a1594f3209937f0a8c45a834e5e7dec9 to your computer and use it in GitHub Desktop.
Aggregate total sizes of prefixes in the S3 bucket
#!/bin/bash
bucket=$1
prefixs=( "${@:2}" )
for prefix in "${prefixs[@]}"
do
size=$(aws s3api list-objects-v2 --bucket="${bucket}" --prefix="${prefix}" | jq '[.Contents[].Size] | add' | numfmt --to=si)
echo "${prefix}\t${size}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment