Finding files in Amazon AWS S3 Buckets

Home » Notes » Finding files in Amazon AWS S3 Buckets

One of my clients uses a 1.5TB sized bucket on Amazon S3 and regularly needs to have a file removed because of copyright claims or something like that. It’s mostly a legacy bucket without any proper file structure. You can imagine searching through all of the folders is something of a nightmare. At least manually. Enter S3 CLI.

Amazon provides for a command line interface that allows you to do various things inside an S3 bucket. Searching for specific files is one of them. Let me share how.

AWS Buckets CLI

Time needed: 2 minutes

There are just a few small steps. Easy peasy if you’re somewhat familiar with the Command Line interface of your machine.

  1. Install AWS CLI

    You’ll want to follow AWS’ installation guide for the CLI first. Once you have everything up and running on your local machine, move to step 2.

  2. Connect your AWS account with AWS CLI

    Follow these steps to make sure your local machine actually knows to which bucket under which AWS account it needs to talk.

  3. Open up your terminal

    Now for the fun part; finding where that file is located. We’re using for the name of the bucket and we’re looking for the following file: aristotle-was-right.jpg.

    To do that, enter this command into your terminal: aws s3 ls s3:// --recursive | grep aristotle-was-right.jpg

  4. Delete your file

    This results in the exact location of the requested file, if it indeed exists. Delete how you see fit. Either by manually navigating to the given folder structure or via the command line you find yourself using. The sky is the limit

Hope this saves you some searching and figuring out.

First name
This field is for validation purposes and should be left unchanged.

Automatically sent to your inbox, just like 🪄 

Leave a Reply

Your email address will not be published. Required fields are marked *