AWS S3 Commands

S3 bucket and object operations

List Buckets

aws s3 ls # list all buckets
aws s3 ls s3://bucket-name # list objects in bucket
aws s3 ls s3://bucket-name/prefix/ # list with prefix

Create and Delete Bucket

aws s3 mb s3://bucket-name # make bucket
aws s3 rb s3://bucket-name # remove empty bucket
aws s3 rb s3://bucket-name --force # remove bucket and all contents

Copy Files

aws s3 cp file.txt s3://bucket-name/ # upload file
aws s3 cp s3://bucket-name/file.txt . # download file
aws s3 cp s3://bucket1/file s3://bucket2/ # copy between buckets
aws s3 cp dir/ s3://bucket-name/ --recursive # upload directory

Sync

aws s3 sync dir/ s3://bucket-name/ # sync local to S3
aws s3 sync s3://bucket-name/ dir/ # sync S3 to local
aws s3 sync s3://bucket1/ s3://bucket2/ # sync between buckets

Move and Remove

aws s3 mv file.txt s3://bucket-name/ # move file to S3
aws s3 rm s3://bucket-name/file.txt # delete object
aws s3 rm s3://bucket-name/ --recursive # delete all objects