Skip to main content
In this guide, you’ll master using the AWS CLI to manage Amazon S3 buckets and objects. We’ll walk through listing buckets, creating buckets, copying and moving files, syncing directories, and cleaning up objects and buckets—all with practical examples.

Prerequisites

  • AWS CLI v2 installed and configured with appropriate IAM permissions.
  • Basic familiarity with your command-line interface (Windows, macOS, or Linux).
If you haven’t installed the AWS CLI, follow the official AWS CLI installation guide.

Quick Reference: Common S3 Commands


1. Listing Buckets and Contents

1.1 List All Buckets

Example output:

1.2 List Objects in a Bucket

Sample:

1.3 Recursive Listing

This shows all objects, including those in nested “folders.”

2. Creating a Bucket

Use mb (make bucket) and specify a region if needed:
Output:
Verify by listing buckets again:

3. Copying Files with cp

3.1 Local → S3

Upload a single file:
Rename while uploading:

3.2 S3 → Local

Download an object to your current directory:

3.3 Bucket-to-Bucket Copy


4. Moving Files with mv

The mv command copies then deletes the source.

4.1 Local → S3

4.2 S3 → Local


5. Copying Directories Recursively

To upload an entire folder:
Verify the structure:

6. Deleting Objects

Remove a single file:
Deleting objects is irreversible. Double-check the object key before running aws s3 rm.

7. Syncing Directories

Make the destination mirror your source directory:
Only new or updated files are transferred.

8. Deleting a Bucket

Attempt to delete an empty bucket:
If the bucket isn’t empty, use:

Watch Video

Practice Lab