How to Find Large Files in an AWS S3 Bucket Using Command Line Interface
Using one simple command

Software Engineer, Content Creator, and Open-Source contributor
Search for a command to run...
Using one simple command

Software Engineer, Content Creator, and Open-Source contributor
No comments yet. Be the first to comment.
In this series, you can find content on software engineering including web development and related technologies.
What is PHP CS Fixer PHP CS Fixer stands for PHP Coding Standards Fixer. This is a tool that fixes your code to follow standards. There are various PHP coding standards that you can follow, such as the popular PSR-1, and PSR-12 published by the PHP ...
I haven't updated my GitHub page for a while and decided to give it a new look. It turned out to be very simple, and it's good if you want your profile to stand out from the millions of others. Also, sometimes recruiters and HR professionals can find...

MVC stands for Model-View-Controller and is a software architecture pattern commonly used to develop software applications. Although originally designed for desktop computing, MVC has been widely adopted as a design for World Wide Web applications in...

Today, more and more people and companies are using TypeScript. It is among the top 10 programming languages in the PYPL index. And this is not surprising, since TypeScript allows you to catch many errors at compile time, not at runtime, that is befo...

When I started working with JavaScript many years ago, I learned that to convert a value to a string, I could use value.toString(). This method worked well and was sufficient to complete the tasks I had at the time. However, as I progressed and start...

If you are new to learning and working with Docker, you might be wondering how Docker images differ from Docker containers. Without further ado, let's dive into it. Both Images and Containers are two distinct concepts in the Docker ecosystem and we n...

I recently struggled to find the right command to search for large files in an AWS S3 bucket and spent many hours researching this topic. I am new to Amazon CloudShell, so I had to ask the community for help, and I even created an account on AWS re:Post (aka the StackOverflow alternative for Amazon Web Services). Although I recommend using it if you need help with AWS, due to the small number of users on re:Post you can usually get help faster on StackOverflow. In my opinion, if you have a question, it is better to ask on both platforms.
For this example, I have chosen Amazon CloudShell as the easiest tool to use with the AWS CLI that does not require any software to be installed on your computer. You can use any other tool you like.
To find the N most recent largest files in an AWS S3 bucket, you need to open console.aws.amazon.com and find CloudShell (I recommend adding it to your favourites in case you need to use it again).

Before running the command you need to know your S3 bucket name. When you have it ready, you can use the command below to find files:
aws s3api list-objects-v2 --bucket BUCKETNAME --query 'sort_by(Contents[?LastModified>=`2023-01-01`], &Size)[-5:]'
Replace BUCKETNAME with your S3 bucket name and change the date (2023-01-01) as needed. After running the command, your output should look like this:

If you want to find the last N files regardless of the LastModified property, you can configure your command like this:
aws s3api list-objects-v2 --bucket BUCKETNAME --query 'sort_by(Contents, &Size)[-5:]'
You can adjust the number of files to be returned by changing the number in the square brackets ([-5:]), or you can remove the square brackets with the contents inside to display all files sorted by size. Be careful to run such a command on a large bucket though, as it can take minutes to perform the operation (I did it once...).
There is another command that I rarely use but thought it would be useful to share.
aws s3 ls --summarize --human-readable --recursive s3://BUCKETNAME
This command will display all files in the bucket in a compact form with LastModified, Size and Name properties. If you have ever run the ls command on a Linux/Unix operating system before, you know what to expect.
The end. I hope you found this information helpful, stay tuned for more content! :)