Skip to content

Instantly share code, notes, and snippets.

@gurdotan
Last active June 1, 2016 13:03
Show Gist options
  • Save gurdotan/c5f66e078767f34702efc59d5db18db8 to your computer and use it in GitHub Desktop.
Save gurdotan/c5f66e078767f34702efc59d5db18db8 to your computer and use it in GitHub Desktop.
S3: sum size of all objects in bucket/folder
IFS=$'\n'; arr=(`for d in {0..182}; do date -d "2015-12-01 + $d days" +'%Y%m%d'; done`); for i in ${arr[@]} ; do aws s3 ls s3://bucket-name/production/dt=$i/ | tr -s " " | cut -f3 -d" " | paste -sd+ - | bc | numfmt --to=iec-i --suffix=B --padding=7 ; done
# S3 list bucket / folder | trim whitespace | cut size field | sum numbers | format to human readable format
aws s3 ls s3://bucket-name/production/dt=20160206/ | tr -s " " | cut -f3 -d" " | paste -sd+ - | bc | numfmt --to=iec-i --suffix=B --padding=7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment