Skip to content

Instantly share code, notes, and snippets.

@fadhlirahim
Created October 4, 2023 01:33
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 fadhlirahim/6430a1a8b594b6a0eeaa469f11c7229a to your computer and use it in GitHub Desktop.
Save fadhlirahim/6430a1a8b594b6a0eeaa469f11c7229a to your computer and use it in GitHub Desktop.
Bash function to get the size of S3 bucket
# Usage:
#
# s3_bucket_size your-bucket-name
#
function s3_bucket_size() {
if [ -z "$1" ]; then
echo "Please provide a bucket name."
return 1
fi
local bucket_name="$1"
aws s3 ls "s3://$bucket_name/" --recursive | awk 'BEGIN {total=0} {total+=$3} END {print total/1024/1024 " MB"}'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment