aws s3 ls s3://$BUCKETNAME/ --recursive --human-readable --summarize | tail -n2
Tail is used because otherwise all files will be printed on screen (but you may want that for some reason).
You just need to add the path to the bucket name:
aws s3 ls s3://$BUCKETNAME/some/dir --recursive --human-readable --summarize | tail -n2
If you imagine there is something like ncdu
or du -ha -d 1 /foo/bar
you're wrong. If you want to get the size of all subdirs you have to do it yourself:
Your Bucket contains in $BUCKETNAME/some/dir
multiple subdirs (for e.g. 2020
, 2019
and 2018
) and you want to see the size of these 3 directories.
S3PATH='s3://$BUCKETNAME/some/dir/'
for dir in $(aws s3 ls "${S3PATH}" | grep PRE | awk '{print $2}'); do
echo "${S3PATH}${dir}:"
aws s3 ls "${S3PATH}${dir}" --recursive \
--human-readable \
--summarize\
| tail -n2
done
A | column
after done
could improve the readability.