Skip to content

Instantly share code, notes, and snippets.

@bool-dev
Forked from joech4n/s3DuByPrefix.sh
Created January 3, 2018 02:39
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 bool-dev/bd6ceed6fc3dc1796b70111bb6221843 to your computer and use it in GitHub Desktop.
Save bool-dev/bd6ceed6fc3dc1796b70111bb6221843 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