How to determine AWS S3 (Simple Storage Service) bucket size from command line:
- Install AWS Cli – Command Line Interface
- Run the following command
aws s3 ls s3://<bucketname> --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'
Where <bucketname> needs to be substituted with the name of the bucket. If the bucket name is “example.com”, the command will be:
aws s3 ls s3://example.com --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'
Bucket size will be returned in MB.