Skip to content

Instantly share code, notes, and snippets.

@joech4n
Last active November 28, 2018 16:40
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save joech4n/43121cfdca74ac69427d to your computer and use it in GitHub Desktop.
Save joech4n/43121cfdca74ac69427d to your computer and use it in GitHub Desktop.
Get bucket size and object count by first level prefix (i.e. bucket/prefix1, bucket/prefix2)
#!/bin/sh
BUCKETNAME=mybucketname; REGION=us-east-1; for prefix in $(aws s3api list-objects --bucket $BUCKETNAME --delimiter '/' --output text --region $REGION |grep COMMONPREFIX |tail -n+2| awk '{print $2}'); do echo "Totals for $prefix"; aws s3 ls --summarize --human-readable --recursive s3://$BUCKETNAME/$prefix --region $REGION ; done |grep Total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment