Created
October 20, 2016 08:03
-
-
Save kevingo/f7e4c01532eba1d7b3837a469f5607c7 to your computer and use it in GitHub Desktop.
Get all s3 bucket size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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