How to use aws s3 ls command – AWS S3 Tutorial

3 weeks ago Lalit Bhagtani 0

In this tutorial, we will learn about how to use aws s3 ls command using aws cli.

ls Command

The ls command is used to get a list of buckets or a list of objects and common prefixes under the specified bucket name or prefix name.

Optional Arguments

This command takes the following optional arguments :-

  1. path :- It is an S3 URI of the bucket or its common prefixes.
  2. –recursive :- It performs list operation for a specified bucket and all of its prefixes.
  3. –page-size (integer) :- It returns the specified number of results in each response to a list operation.
  4. –human-readable :- It displays file sizes in a human readable format.
  5. –summarize :- It displays summary information like the number of objects and total size.
  6. –request-payer (String) :- It confirms that the requester knows that she or he will be charged for the request. Bucket owners need not to specify this parameter in their requests.

Syntax 

aws s3 ls <S3Uri> [--recursive] [--pagesize] [--summarize] [--human-readable]

Examples

Get Bucket List

The aws s3 ls command can be used to get a list of buckets owned by the user. The syntax of the command is as follows:-

Syntax

aws s3 ls

Output

<Created Date> <Bucket Name> 

Example

aws s3 ls

Get Objects & Prefixes of Bucket

The aws s3 ls command with the s3Uri option can be used to get a list of objects and common prefixes under the specified bucket name or prefix name. The syntax of the command is as follows:-

Syntax

aws s3 ls <s3Uri>

Output

                PRE   <Prefix Name> 
<Created Date> <Size> <Object Name> 

Example

aws s3 ls

Get all Objects & Prefixes of Bucket

The aws s3 ls command with the s3Uri and the recursive option can be used to get a list of all the objects and common prefixes under the specified bucket name or prefix name. The syntax of the command is as follows:-

Syntax

aws s3 ls <s3Uri> --recursive

Output

<Created Date> <Bucket Name>
<Created Date> <Prefix Name>

Example

aws s3 ls

References :-

  1. S3 ls Command Docs

If you liked it, please share your thoughts in comments section and share it with others too.