Skip to content

Instantly share code, notes, and snippets.

@andgineer
Last active December 20, 2022 05:52
Show Gist options
  • Save andgineer/7da3ae95d5980b9c25fcd44c3a607841 to your computer and use it in GitHub Desktop.
Save andgineer/7da3ae95d5980b9c25fcd44c3a607841 to your computer and use it in GitHub Desktop.
Equivalent of "du" command for a Amazon S3 bucket's "folder". Shows sizes of "subfolders" in this "folder".
function s3du {
readonly folder_to_scan=${1:?"The argument 's3://bucket/folder_to_scan/' must be specified."}
for subfolder in $(aws s3 ls "${folder_to_scan}" | grep PRE | awk '{print $2}'); do
echo "${folder_to_scan}${subfolder}:"
aws s3 ls "${folder_to_scan}${subfolder}" --recursive \
--human-readable \
--summarize \
| tail -n2
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment