Month: October 2021

Listing sizes in AWS S3 Buckets

Getting the whole bucket size

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).

Getting the size of a specific directory/file

You just need to add the path to the bucket name:

aws s3 ls s3://$BUCKETNAME/some/dir --recursive --human-readable --summarize | tail -n2

Getting the size of all subdirs

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.

Send A Test Mail via Exim Command line

Sending a test mail from a server with a configured exim is easy as pie.

From your user shell:

  1. tell exim that we want to send a mail to an recipient and tell us about the details of the sending procedure
    $ exim -v receipient@foo.bar
    
  2. Tell exim about the sender, the subject and input some text.
    From: user@your.domain.example
    Subject: Foobar
    Text Text Text
    
    I like Pie!
    
  3. Press Ctrl+d
  4. You should see the details about the SMTP connection. You can return to your shell with Ctrl+c