List All Of The Files Of An S3 Bucket With The AWS CLI

How To list all of the files of an S3 bucket with the AWS CLI

There are some ways to list all of the files of an S3 bucket with the AWS CLI. This tutorial will help you know how to do it with explanations and examples below.

List All Of The Files Of An S3 Bucket With The AWS CLI

What is Amazon S3?

Amazon Simple Storage Service (S3) is a storage that can be maintained and accessed over the Internet.

Organizations of any size in any industry can use this service. It is used in many cases such as websites, archiving, mobile apps, data backups, IoT devices, restorations and enterprise application storage.

Method 1: Using the s3api list-buckets command

You can achieve this by one single command.

For example, run the following command:

aws s3api list-buckets

Its results will display in a form that looks like this:

aws s3api list-buckets -- profile username

Output 

{
    "Buckets": [
        {
            "Name": "learnshareit",
            "CreationDate": "2022-12-12T10:24:06.000z"
        },
        {
            "Name": "manchesterunited",
            "CreationDate": "2022-12-11T15:50:38.000z"
        },
        {
            "Name": "test-bucket-cli",
            "CreationDate": "2022-11-10T05:42:06.000z"
        },
        {
            "Name": "maguire-1",
            "CreationDate": "2022-09-11T07:15:22.000z"
        },
        {
            "Name": "maguire-2",
            "CreationDate": "2022-12-13T07:55:06.000z"
        },
        {
            "Name": "player-1",
            "CreationDate": "2022-11-14T08:15:16.000z"
        }
        {
            "Name": "player-2”,
            "CreationDate": "2022-11-13T18:16:02.000z"
        }
    ],
    "Owner": {
        "DisplayName": "username",
        "ID": "a60192cb6fff908bc7548cba6667bc0ffea907cbf0cff"
    }
}

Method 2: Using the s3 ls command

Alternatively, you can also use the s3 ls command to return the same result, for example:

aws s3 ls

Look at the result when I use it below.

aws s3 ls -- profile username

Output

2022-09-07 10:20:30 learn-share-it
2022-09-06 08:15:13 data-sql
2022-09-06 07:14:33 data-txt
2022-09-06 06:25:46 test-bucket
2022-09-06 06:15:15 real-madrid-player
2022-09-06 06:10:53 mu-player
2022-09-06 06:05:22 student
2022-09-06 05:55:05 teacher-tt
2022-09-06 05:50:05 player-1
2022-09-06 05:48:53 player-2
2022-09-06 05:47:29 English-1
2022-09-06 05:40:35 teacher-2
2022-09-06 05:37:26 teacher-1

Summary

You can use the s3api list-buckets or the s3 ls command to list all of the files of an S3 bucket with the AWS CLI. We hope this guide is helpful to you. Thanks!

Maybe you are interested:

Posted in AWS

Leave a Reply

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