Skip to content

Instantly share code, notes, and snippets.

@kevingo
Created October 20, 2016 08:03
Show Gist options
  • Select an option

  • Save kevingo/f7e4c01532eba1d7b3837a469f5607c7 to your computer and use it in GitHub Desktop.

Select an option

Save kevingo/f7e4c01532eba1d7b3837a469f5607c7 to your computer and use it in GitHub Desktop.
Get all s3 bucket size
#!/bin/sh
# Report S3 bucket sizes
get_bucket_size() {
bucket="$1"
aws s3 ls s3://"$bucket" --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'
}
buckets=$(s3cmd ls |awk '{sub("^s3://","",$3); print $3}')
for bucket in $buckets; do
echo "$bucket" $(get_bucket_size "$bucket")
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment