Skip to content

Instantly share code, notes, and snippets.

@2matzzz
Created February 9, 2017 14:04
Show Gist options
  • Save 2matzzz/88dba42fb6080b9d1b2972cb395b351d to your computer and use it in GitHub Desktop.
Save 2matzzz/88dba42fb6080b9d1b2972cb395b351d to your computer and use it in GitHub Desktop.
s3calc
#!/bin/bash
regex='(s3)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [[ $@ =~ $regex ]]
then
aws s3 ls $@ --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024/1024" GB"}'
else
echo "format err, input e.g. s3://bucket/path/to/calc"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment