AWS S3 CLI Commands Reference
Frequently used AWS CLI commands for managing S3 buckets and objects.
Sync between buckets (same or different accounts)
# Sync with bucket-owner ACL (required when copying across accounts)
aws s3 sync s3://source-bucket/ s3://destination-bucket/ --acl bucket-owner-full-control
# Sync with a named profile (for cross-account)
aws s3 sync s3://source-bucket/ s3://destination-bucket/ --acl bucket-owner-full-control --profile source-account-profile
Copy / move objects
# Copy a single file
aws s3 cp s3://bucket/file.txt s3://other-bucket/file.txt
# Move (copy then delete)
aws s3 mv s3://bucket/file.txt s3://bucket/archive/file.txt
# Copy all objects matching a prefix
aws s3 cp s3://bucket/logs/ s3://archive-bucket/logs/ --recursive
List and inspect
# List buckets
aws s3 ls
# List objects in a bucket
aws s3 ls s3://my-bucket --recursive --human-readable
# Get object metadata
aws s3api head-object --bucket my-bucket --key path/to/file.txt
Bucket operations
# Create a bucket
aws s3 mb s3://my-new-bucket --region us-east-1
# Delete all objects in a bucket (empty it)
aws s3 rm s3://my-bucket --recursive
# Delete the bucket (must be empty)
aws s3 rb s3://my-bucket
Presigned URLs (temporary access)
# Generate a URL valid for 1 hour (3600 seconds)
aws s3 presign s3://my-bucket/private-file.pdf --expires-in 3600