This AWS S3 CLI cheat sheet provides quick reference for the most commonly used S3 commands. Bookmark this page for easy access to aws s3 cp, aws s3 ls, aws s3 sync, and other essential commands.
Prerequisites
Ensure AWS CLI is installed and configured:
# Install AWS CLI (if not installed)
pip install awscli
# Configure credentials
aws configure
# Verify access
aws s3 lsaws s3 ls - List Buckets and Objects
| Command | Description |
|---|---|
aws s3 ls | List all buckets |
aws s3 ls s3://bucket-name/ | List objects in bucket root |
aws s3 ls s3://bucket/prefix/ | List objects in folder |
aws s3 ls s3://bucket/ --recursive | List all objects (all levels) |
aws s3 ls s3://bucket/ --human-readable | Show file sizes in KB/MB/GB |
aws s3 ls s3://bucket/ --summarize | Show total count and size |
Examples
# List all buckets
aws s3 ls
# List objects with human-readable sizes
aws s3 ls s3://my-bucket/ --human-readable --summarize
# List recursively and count objects
aws s3 ls s3://my-bucket/ --recursive --summarizeaws s3 cp - Copy Files
| Command | Description |
|---|---|
aws s3 cp file.txt s3://bucket/ | Upload file to bucket |
aws s3 cp s3://bucket/file.txt ./ | Download file from bucket |
aws s3 cp s3://src/file s3://dest/ | Copy between buckets |
aws s3 cp . s3://bucket/ --recursive | Upload folder recursively |
aws s3 cp s3://bucket/ . --recursive | Download folder recursively |
Useful Flags
| Flag | Description |
|---|---|
--recursive | Copy directories recursively |
--exclude "pattern" | Exclude files matching pattern |
--include "pattern" | Include files matching pattern |
--acl public-read | Make uploaded files public |
--storage-class STANDARD_IA | Set storage class |
--dryrun | Show what would be copied |
Examples
# Upload file
aws s3 cp report.pdf s3://my-bucket/reports/
# Download file with different name
aws s3 cp s3://my-bucket/data.csv ./local-data.csv
# Upload folder, excluding hidden files
aws s3 cp ./website s3://my-bucket/ --recursive --exclude ".*"
# Upload with specific content type
aws s3 cp index.html s3://bucket/ --content-type "text/html"
# Copy between buckets
aws s3 cp s3://source-bucket/data/ s3://dest-bucket/backup/ --recursiveaws s3 sync - Synchronize Directories
sync only transfers new or modified files, making it efficient for backups and deployments.
| Command | Description |
|---|---|
aws s3 sync . s3://bucket/ | Upload new/changed files |
aws s3 sync s3://bucket/ . | Download new/changed files |
aws s3 sync s3://src/ s3://dest/ | Sync between buckets |
aws s3 sync . s3://bucket/ --delete | Mirror: delete files not in source |
Sync Flags
| Flag | Description |
|---|---|
--delete | Delete destination files not in source |
--exact-timestamps | Compare by timestamp (not size) |
--size-only | Compare by size only (ignore timestamp) |
--exclude | Skip files matching pattern |
--include | Include files matching pattern |
--dryrun | Preview without making changes |
Examples
# Sync local folder to S3
aws s3 sync ./build s3://my-website/
# Sync with delete (mirror)
aws s3 sync ./build s3://my-website/ --delete
# Sync excluding certain files
aws s3 sync . s3://bucket/ --exclude "*.log" --exclude "temp/*"
# Preview sync without executing
aws s3 sync . s3://bucket/ --dryrun
# Sync only specific file types
aws s3 sync . s3://bucket/ --exclude "*" --include "*.jpg" --include "*.png"aws s3 rm - Delete Objects
| Command | Description |
|---|---|
aws s3 rm s3://bucket/file.txt | Delete single file |
aws s3 rm s3://bucket/folder/ --recursive | Delete folder recursively |
aws s3 rm s3://bucket/ --recursive | Empty entire bucket |
Examples
# Delete single object
aws s3 rm s3://my-bucket/old-file.txt
# Delete all objects in folder
aws s3 rm s3://my-bucket/logs/ --recursive
# Delete with preview
aws s3 rm s3://my-bucket/temp/ --recursive --dryrun
# Delete only .log files
aws s3 rm s3://my-bucket/ --recursive --exclude "*" --include "*.log"aws s3 mv - Move/Rename Objects
| Command | Description |
|---|---|
aws s3 mv s3://bucket/old.txt s3://bucket/new.txt | Rename file |
aws s3 mv s3://bucket/file.txt s3://other/ | Move between buckets |
aws s3 mv ./file.txt s3://bucket/ | Upload and delete local |
aws s3 mv s3://bucket/folder/ s3://bucket/new/ --recursive | Move folder |
Bucket Management Commands
| Command | Description |
|---|---|
aws s3 mb s3://new-bucket | Create bucket |
aws s3 rb s3://bucket | Remove empty bucket |
aws s3 rb s3://bucket --force | Remove bucket and all contents |
# Create bucket in specific region
aws s3 mb s3://my-new-bucket --region us-west-2
# Delete bucket (must be empty)
aws s3 rb s3://old-bucket
# Force delete bucket with all contents
aws s3 rb s3://old-bucket --forcePerformance Optimization
Configure concurrent requests for faster transfers:
# Increase max concurrent requests (default: 10)
aws configure set default.s3.max_concurrent_requests 20
# Increase multipart threshold (default: 8MB)
aws configure set default.s3.multipart_threshold 64MB
# Increase multipart chunk size
aws configure set default.s3.multipart_chunksize 16MBQuick Reference Card
| Task | Command |
|---|---|
| List buckets | aws s3 ls |
| Upload file | aws s3 cp file.txt s3://bucket/ |
| Download file | aws s3 cp s3://bucket/file.txt ./ |
| Upload folder | aws s3 cp ./folder s3://bucket/ --recursive |
| Sync folder | aws s3 sync ./folder s3://bucket/ |
| Delete file | aws s3 rm s3://bucket/file.txt |
| Empty bucket | aws s3 rm s3://bucket/ --recursive |
| Create bucket | aws s3 mb s3://new-bucket |
| Delete bucket | aws s3 rb s3://bucket --force |