The following is a guide on how to list the largest items in an S3 bucket from the terminal. This guide is for AWS users, but it can be easily adapted to other cloud platforms.

  1. Log in to your AWS account and open the terminal.
  2. Type “s3 ls” into the terminal and press enter.
  3. The output will show you the contents of your S3 bucket, including its size and objects. You can see that there are a total of 9 items in your bucket, with an object size of 1MB.

If you’re curious about the largest items in an AWS S3 bucket, you can use the CLI to print out a list sorted by size. This can help you locate unusually large objects in the bucket which may be taking up space.

Listing and Sorting Items with the S3 CLI

S3 provides some built in sorting options in the menus, so if you’re just looking for the largest item in a folder, you can simply sort that folder. However, if you want to search for all items regardless of key, you’ll need to do so from the AWS CLI. If you don’t have that installed, you can refer to our guide on configuring it to set it up.

The command for listing objects is pretty simple:

This query can take a while to evaluate, since it’s downloading a master list of all objects and their metadata, but you’ll get a JSON array containing an entry for each item, like the following:

To parse and sort this, you can use jq — a fantastic utility for working with JSON on the command line. You can download it from apt, though binaries are also available:

This makes the final command the following, which will still take a while to evaluate, but will print out the largest 100 items in the bucket:

If you want more or less items, you can change the input parameter to the head command, which trims all but the first N lines.