Created
February 28, 2018 17:57
-
-
Save bduggan/1435b3f23943222a658d93dbf996697a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# du.sh -- find usage of an s3 bucket and directory (recursively) | |
# | |
# Usage: | |
# | |
# du.sh <bucket> <directory> | |
# | |
# requires jq, perl, aws-cli | |
BUCKET=$1 | |
DIR=$2 | |
[ -z "$DIR" ] && echo "usage: du.sh <bucket> <directory>" && exit | |
aws s3api list-objects --bucket $BUCKET --prefix $DIR \ | |
| jq -r '.Contents[] | [ .Size, .Key ] | @tsv' \ | |
| perl -lan \ | |
-e ' | |
@parts = split("/",$F[1]); | |
for (0..@parts-1) { | |
$du{join "/",@parts[0..$_]} += $F[0] | |
}; | |
END { | |
printf "%10s $_\n",$du{$_},$_ | |
for sort { +$du{$b} <=> +$du{$a} } keys %du | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment