AWS S3 CLI Commands Cheat Sheet (cp, ls, sync, and More)

Complete AWS S3 CLI cheat sheet with syntax, examples, and common use cases for aws s3 cp, aws s3 ls, aws s3 sync, and other essential commands.

8 min readUpdated January 2025

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 ls

aws s3 ls - List Buckets and Objects

CommandDescription
aws s3 lsList 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/ --recursiveList all objects (all levels)
aws s3 ls s3://bucket/ --human-readableShow file sizes in KB/MB/GB
aws s3 ls s3://bucket/ --summarizeShow 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 --summarize

aws s3 cp - Copy Files

CommandDescription
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/ --recursiveUpload folder recursively
aws s3 cp s3://bucket/ . --recursiveDownload folder recursively

Useful Flags

FlagDescription
--recursiveCopy directories recursively
--exclude "pattern"Exclude files matching pattern
--include "pattern"Include files matching pattern
--acl public-readMake uploaded files public
--storage-class STANDARD_IASet storage class
--dryrunShow 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/ --recursive

aws s3 sync - Synchronize Directories

sync only transfers new or modified files, making it efficient for backups and deployments.

CommandDescription
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/ --deleteMirror: delete files not in source

Sync Flags

FlagDescription
--deleteDelete destination files not in source
--exact-timestampsCompare by timestamp (not size)
--size-onlyCompare by size only (ignore timestamp)
--excludeSkip files matching pattern
--includeInclude files matching pattern
--dryrunPreview 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

CommandDescription
aws s3 rm s3://bucket/file.txtDelete single file
aws s3 rm s3://bucket/folder/ --recursiveDelete folder recursively
aws s3 rm s3://bucket/ --recursiveEmpty 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

CommandDescription
aws s3 mv s3://bucket/old.txt s3://bucket/new.txtRename 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/ --recursiveMove folder

Bucket Management Commands

CommandDescription
aws s3 mb s3://new-bucketCreate bucket
aws s3 rb s3://bucketRemove empty bucket
aws s3 rb s3://bucket --forceRemove 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 --force

Performance 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 16MB

Quick Reference Card

TaskCommand
List bucketsaws s3 ls
Upload fileaws s3 cp file.txt s3://bucket/
Download fileaws s3 cp s3://bucket/file.txt ./
Upload folderaws s3 cp ./folder s3://bucket/ --recursive
Sync folderaws s3 sync ./folder s3://bucket/
Delete fileaws s3 rm s3://bucket/file.txt
Empty bucketaws s3 rm s3://bucket/ --recursive
Create bucketaws s3 mb s3://new-bucket
Delete bucketaws s3 rb s3://bucket --force

Frequently Asked Questions

Find answers to common questions

aws s3 cp copies files from source to destination every time it runs. aws s3 sync only transfers files that are new or modified, comparing source and destination. Use cp for single files or when you always want to overwrite. Use sync for efficient incremental backups and large directory transfers.

Need Professional Help?

Our team of experts can help you implement and configure these solutions for your organization.