Created
October 4, 2023 01:33
-
-
Save fadhlirahim/6430a1a8b594b6a0eeaa469f11c7229a to your computer and use it in GitHub Desktop.
Bash function to get the size of S3 bucket
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
# 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