Useful AWS S3 CLI Commands

Posted August 17, 2022 by Rohith ‐ 2 min read

AWS S3 cli is useful tool while operating on s3 object store. This article list useful aws s3 cli commands frequently used. It can be a quick reference to anyone who is looking for quick solutions.

TL;DR

use following option while listing or deleting objects

OptionDescription
--recursivelist the objects recursively
--human-readablelist the size in human-readable format
--summarizeshow the total size of listed objects
--includeinclude the files in the list
--excludeexclude the files in the list
--request-payer=requestercharge the requester for listing s3 objects

List Objects

S3 objects can be listed using following syntax.

Syntax:

aws s3 ls [options] s3://<bucket-name>/<path>/ 

Example:

aws s3 ls s3://my-s3-bucket/campaigns/

List Objects Recursively

ls with --recursive option is used to recursively list the items

Example:

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

List Objects In Readable Size Format

ls with --human-readable option is used to recursively list the items

Example:

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

List Objects And Total Size

ls with --summarize option is used to list the items and the total size of objects listed.

Example:

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

Filter List Objects Using Include And Exclude

ls with --include and --exclude options are used to filter and list the filtered items.

Example: Below example lists objects which only has 2022 in the object name.

aws s3 ls --exclude "*"  --include "*2022-*" s3://my-s3-bucket/campaigns/

List Objects With Request Payer

Usually, when we fire list command, s3 is billed for the account who owns the bucket. Instead if we want requester to be payer, use ls with --request-payer=requester option.

Example:

aws s3 ls --request-payer=requester s3://my-s3-bucket/campaigns/

Remove Objects

S3 objects can be removed using following syntax.

Syntax:

aws s3 rm [options] s3://<bucket-name>/<path>/<object-name>

Example:

aws s3 rm s3://my-s3-bucket/campaigns/banner-ads.csv

Remove Objects Recursively

rm with --recursive option is used to recursively removes the items

Example:

aws s3 rm --recursive s3://my-s3-bucket/campaigns/
quick-references aws s3 blog

Subscribe For More Content