2026-02-17

AWS S3 LS Command Guide: Examples, Options, and Filtering

AWSS3CLICloud
A

AWS S3 LS Command Guide: Examples, Options, and Filtering

The AWS CLI (Command Line Interface) is a powerful tool for managing your cloud resources. In this guide, we will deep dive into one of the most commonly used commands: aws s3 ls. You will learn how to list buckets, check object sizes, and use advanced filtering options.

<div class="toc"> <h3>Table of Contents</h3> <ul> <li><a href="#basic-usage">Basic Usage</a></li> <li><a href="#listing-bucket-contents">Listing Bucket Contents</a></li> <li><a href="#recursive-listing">Recursive Listing</a></li> <li><a href="#human-readable-sizes">Human Readable Sizes</a></li> <li><a href="#summarizing-results">Summarizing Results</a></li> <li><a href="#filtering-with-grep">Filtering with Grep</a></li> <li><a href="#frequently-asked-questions">Frequently Asked Questions</a></li> </ul> </div>

Basic Usage

To list all S3 buckets in your AWS account, simply use the aws s3 ls command:

aws s3 ls

Example Output:

2023-05-28 20:33:12 awsfundamentals-content
2022-07-11 13:49:22 awsfundamentals-landing

This lists the creation date and the name of each bucket.

Listing Bucket Contents

To list objects within a specific bucket or folder (prefix), specify the bucket name (or path):

aws s3 ls s3://my-bucket-name/folder/

Recursive Listing

By default, the ls command only shows objects in the specified directory. To see all files in subdirectories, use the --recursive flag:

aws s3 ls s3://my-bucket-name/ --recursive

This will list all files in all subdirectories.

Human Readable Sizes

To view file sizes in a more understandable format like MiB or KiB instead of bytes, add the --human-readable parameter:

aws s3 ls s3://my-bucket-name/ --human-readable

Example Output:

2022-08-15 17:54:40   10.6 MiB api-gateway.pdf
2022-08-15 17:54:40    3.5 MiB api-gateway.webp

Summarizing Results

To see the total number of objects and total size, you can use the --summarize parameter:

aws s3 ls s3://my-bucket-name/ --summarize

The total object count and total size will be displayed at the end of the output.

Filtering with Grep

The aws s3 ls command does not support direct filtering (like SQL WHERE). However, on Linux/Unix systems, you can pipe the output to grep. For example, to list only PDF files:

aws s3 ls s3://my-bucket-name/ | grep .pdf

Frequently Asked Questions

What is the AWS S3 LS command used for?

The AWS S3 LS command is used to list S3 buckets or objects within a bucket.

How can I list subfolders?

You can list all subfolders and files in a bucket using the --recursive parameter.

How can I make file sizes more readable?

The --human-readable parameter displays file sizes in units like KB and MB instead of bytes.

For more information, visit the Official AWS Documentation. Also, check out our AWS Consultancy services for cloud solutions.

<p>Kaynak / Source: https://awsfundamentals.com/blog/aws-s3-ls</p>