Skip to content

Instantly share code, notes, and snippets.

@kshailen
Created May 7, 2020 11:37
Show Gist options
  • Save kshailen/d16432cc33e964cdb20c6c9849acf58b to your computer and use it in GitHub Desktop.
Save kshailen/d16432cc33e964cdb20c6c9849acf58b to your computer and use it in GitHub Desktop.
Get Size details of all S3 buckets
#!/bin/bash
# exit when the command fails
set -o errexit;
# exit when try to use undeclared var
set -o nounset;
Total_num_of_buckets=`aws s3 ls s3:// | awk '{print $NF}'| wc -l`
printf "%s: %4d\n" "Total Number of s3 buckets" ${Total_num_of_buckets}
printf "%s: %4s\n" "Bucket Name" "Bucket Size"
for bucket in `aws s3 ls s3:// | awk '{print $NF}'`; do printf "$bucket :"; aws s3 ls s3://$bucket --recursive --human-readable --summarize | tail -1 | tr -d 'Total Size:'; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment