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.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
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
| Operation | Command | Description |
|---|---|---|
| List all buckets | aws s3 ls | Show every S3 bucket in your AWS account |
| List bucket contents | aws s3 ls s3://BUCKET_NAME | Display objects in a specific bucket |
| Create a new bucket | aws s3 mb s3://BUCKET_NAME | Make a new bucket (region optional with --region) |
| Copy files | aws s3 cp SOURCE DESTINATION | Copy files between local and S3 or between buckets |
| Move files | aws s3 mv SOURCE DESTINATION | Move files (source deleted after successful copy) |
| Sync directories | aws s3 sync SOURCE DESTINATION | Mirror a directory (uploads only new or changed files) |
| Delete objects | aws s3 rm s3://BUCKET_NAME/OBJECT | Remove a single object |
| Delete a bucket | aws s3 rb s3://BUCKET_NAME | Remove a bucket (use --force to delete all objects first) |
1. Listing Buckets and Contents
1.1 List All Buckets
1.2 List Objects in a Bucket
1.3 Recursive Listing
2. Creating a Bucket
Usemb (make bucket) and specify a region if needed:
3. Copying Files with cp
3.1 Local → S3
Upload a single file: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:6. Deleting Objects
Remove a single file:Deleting objects is irreversible. Double-check the object key before running
aws s3 rm.