Prerequisites
- AWS CLI installed and configured (
aws configure) - IAM permissions to list, create, and delete S3 buckets and objects
- Unique bucket names (globally unique across AWS)
Before creating a bucket, verify the name’s availability. Bucket names must be globally unique and compliant with DNS naming conventions.
Quick Reference: Common S3 CLI Commands
| Operation | Command | Description |
|---|---|---|
| List Buckets | aws s3 ls | Display all S3 buckets in the account |
| Create Bucket | aws s3 mb s3://<bucket-name> --region ... | Make a new bucket in a specified region |
| Delete Bucket | aws s3 rb s3://<bucket-name> [--force] | Remove an empty bucket or delete recursively |
| List Objects | aws s3 ls s3://<bucket> | Show top-level objects and prefixes |
| Copy Files/Dirs | aws s3 cp <src> <dest> [--recursive] | Copy files between local and S3 |
| Move Files/Dirs | aws s3 mv <src> <dest> [--recursive] | Move files between local and S3 |
| Sync Directories | aws s3 sync <local> s3://<bucket> | Sync only new or changed files |
| Delete Objects | aws s3 rm s3://<bucket>/<key> [--recursive] | Remove objects or entire prefixes |
1. Listing S3 Buckets
Retrieve all buckets in your AWS account:2. Creating a New Bucket
Use the make bucket command and specify a region:3. Deleting a Bucket
Remove an empty bucket:--force:
Using
--force is irreversible. All objects in the bucket will be permanently deleted.4. Listing Objects Inside a Bucket
4.1 Top-Level Listing
List prefixes (folders) and files at the root of the bucket:4.2 Recursive Listing
Show every object under the bucket:5. Copying Files
5.1 Local → S3
Upload a file without deleting the source:5.2 S3 → Local
Download an object to a local directory:5.3 S3 → S3
Copy between two buckets:6. Deleting Objects
6.1 Single Object
6.2 Multiple Objects (Recursive)
7. Directory Operations
Most S3 CLI commands support--recursive to process all files under a directory or prefix.
7.1 Copy an Entire Directory
7.2 Move Files and Directories
Usemv to transfer and remove the source:
8. Synchronizing Directories
Keep a local folder and an S3 prefix in sync. Only new or updated files transfer:etc/ssh) and rerunning uploads only those: