A simple guide to the AWS S3 CLI

The AWS command line interface is the goto tools from which you can perform pretty much any operation that relates to AWS. This post only cover the most common operations:

If that’s not already the case, you first need to install and configure the AWS CLI.

List Files and buckets

list your buckets:

~/$ aws s3 ls
2018-07-18 23:27:57 kerjean
2018-05-14 17:46:08 orgmode-emacs
2018-11-15 13:10:20 testgithubissue

list files in a bucket:

~/$ aws s3 ls kerjean/
PRE test/
2019-02-26 20:57:12 7 encrypted.txt
2020-05-17 02:20:18 557 releasenote.org
2018-08-01 19:43:01 15 test2.txt

list files under a key:

~/$ aws s3 ls kerjean/test/
2020-02-05 01:50:22 0
2020-05-27 22:06:08 79 mytextfile.txt
2020-02-05 01:50:32 7 test.txt

list files in a bucket in a recursive manner:

~/$ aws s3 ls --recursive kerjean/
2019-02-26 20:57:12 7 encrypted.txt
2020-05-17 02:20:18 557 releasenote.org
2020-02-05 01:50:22 0 test/
2020-05-27 22:06:08 79 test/mytextfile.txt
2020-02-05 01:50:32 7 test/test.txt
2018-08-01 19:43:01 15 test2.txt

Manage data on S3

create a bucket:

~/$ aws s3 mb s3://testing-tutorial
make_bucket: testing-tutorial

upload a folder:

~/$ aws s3 sync local s3://testing-tutorial/local/
upload: local/bar.txt to s3://testing-tutorial/local/bar.txt
upload: local/foo.txt to s3://testing-tutorial/local/foo.txt
~/$ echo "lorem ipsum" > local/foo.txt
~/$ aws s3 sync local s3://testing-tutorial/local/
upload: local/foo.txt to s3://testing-tutorial/local/foo.txt

upload a file:

~/$ aws s3 cp local/foo.txt s3://testing-tutorial/local/foobar.txt
upload: local/foo.txt to s3://testing-tutorial/local/foobar.txt

rename a file:

~/$ aws s3 mv s3://testing-tutorial/local/foobar.txt s3://testing-tutorial/local/foo/foo.txt
move: s3://testing-tutorial/local/foobar.txt to s3://testing-tutorial/local/foo/foo.txt

download a file:

~/$ aws s3 mv s3://testing-tutorial/local/foo.txt new.txt
move: s3://testing-tutorial/local/foo.txt to ./new.txt

download a folder:

~/$ aws s3 sync s3://testing-tutorial/local/ local
download: s3://testing-tutorial/local/foo/foo.txt to local/foo/foo.txt

remove a file:

~/$ aws s3 rm s3://testing-tutorial/local/foo.txt
delete: s3://testing-tutorial/foo.txt

remove a folder:

~/$ aws s3 rm --recursive s3://testing-tutorial/local/
delete: s3://testing-tutorial/local/bar.txt
delete: s3://testing-tutorial/local/foo/foo.txt

remove an entire bucket with its content:

~/$ aws s3 rb --force s3://testing-tutorial
remove_bucket: testing-tutorial
While you're at it, check our S3 browser: