10 Best s3cmd Command Examples for AWS Cloud Administrators


In this article, we will look at the s3cmd command examples. S3 is known as simple storage service where we can store almost any kind of objects. We will learn here how to access files from S3 storage using s3cmd command line tool. This tool will be very much useful if you want to access the storage through any bash or other linux script. You can programmatically upload or download the files from storage.

10 Best s3cmd Command Examples for AWS Cloud Administrators

s3cmd Command Examples

Also Read: Create an EC2 Instance in AWS with 7 Easy Steps

Example 1: Create a S3 Bucket

If you want to create a S3 Bucket, then you need to use below command. In this example, I am creating a bucket called test-example. Please note that here bucket name starts with s3:// prefix. If you forget this URI in the command, then you will get "Expecting S3 URI with just the bucket name set instead of '<bucket_name>'" error.

[root@localhost ~]# s3cmd mb s3://test-example1
Bucket 's3://test-example1/' created


Example 2: List a Bucket 

If you want to list a bucket and all its files, then you need to use below command. Here you can see that we are using ls option to list test-example1 bucket and its contents.

[root@localhost ~]# s3cmd ls test-example1
2017-06-14 11:17 s3://demo
2019-08-21 06:54 s3://example
2018-07-17 05:49 s3://atest-e3ea7edb7ce2b7ec29714b9256e21944
2017-03-21 01:58 s3://atest
2016-03-27 04:43 s3://test-templates-1uwg86dfc53aq-us-east-1
2011-12-08 17:19 s3://test-templates-1uwg86dfc53aq-us-east-2
2011-08-22 17:33 s3://test-templates-1uwg86dfc53aq-us-west-1
2011-03-28 09:40 s3://test-templates-1uwg86dfc53aq-us-west-2
2011-09-27 09:08 s3://test1
2011-02-12 08:09 s3://customer


Example 3: List all Buckets

If you want to list and see all the buckets in AWS account and its files then you need to use la option instead of ls to check that. Please note that this command output will be in detail based on number of buckets and its contents.

[root@localhost ~]# s3cmd la
2011-06-14 11:21 1925034 s3://yourbucket/test.html
2011-06-18 15:10 1158 s3://yourbucket/example.html
2011-01-30 08:10 1213151 s3://yourbucket/test1.tar.gz
2011-11-11 17:37 5001 s3://yourbucket/test.jpg
2011-01-23 06:59 1714520 s3://yourbucket/example2.tar.gz
2011-02-14 20:19 291 s3://yourbucket/
2011-03-23 00:34 7772680 s3://yourbucket/test
2011-06-14 11:30 27 s3://yourbucket/test.txt

2011-02-26 07:25 528338576 s3://morebucket/test.upg
2011-08-21 06:54 630004352 s3://morebucket/test1.upg
2011-09-09 08:24 619328784 s3://morebucket/test2.upg
2011-09-09 08:24 622524160 s3://morebucket/test3.upg
2011-10-01 09:36 742018384 s3://morebucket/test4.upg
2011-11-24 03:24 743647520 s3://morebucket/test5.upg
2011-11-27 06:12 8211 s3://morebucket/


Example 4: Copy Files into Bucket

If you want to copy some file into your bucket, then first you need to create a file using touch command as shown below. In this example, we are creating an empty file example.txt.

[root@localhost ~]# touch example.txt

Now you can upload example.txt in the bucket using put option as mentioned below. Since example.txt is an empty file hence it will be quickly uploaded.

[root@localhost ~]# s3cmd put example.txt s3://test-example1
upload: 'example.txt' -> 's3://test-example1/example.txt' [1 of 1]
0 of 0 0% in 0s 0.00 B/s done


Example 5: Get the file from Bucket

If you want to get some files from your bucket to your local system, then you need to use below s3cmd command. As you can check from below output, here we are using get option to download a file from S3 Bucket whereas we have used put option above to upload a file.

[root@localhost ~]# s3cmd get s3://test-example3/example.txt example.txt
download: 's3://test-example3/example.txt' -> 'example.txt' [1 of 1]
0 of 0 0% in 0s 0.00 B/s done


Example 6: Delete a File from Bucket

If you want to delete a file from bucket, then you need to use below command. You can notice from below command that we are using del option to delete a file from bucket. Here we are deleting example.txt file from test-example3 bucket.

[root@localhost ~]# s3cmd del s3://test-example3/example.txt
delete: 's3://test-example3/example.txt'


Example 7: Delete a Bucket

If you want to delete a bucket, then you need to use below command. Please note that before deleting a bucket, you need to remove all the files from bucket and empty it or else you will get "The bucket you tried to delete is not empty".

[root@localhost ~]# s3cmd rb s3://test-example3
Bucket 's3://test-example3/' removed


Example 8: Copy Files from One Bucket to Another

You can copy files from one bucket to another by using below command. Here we are copying example.txt file from source bucket test-exampl3 to destination bucket test-example1.

[root@localhost ~]# s3cmd cp s3://test-exampl3/example.txt s3://test-example1
remote copy: 's3://test-exampl3/example.txt' -> 's3://test-example1/example.txt'


Example 9: Check Info of a Bucket

If you want to get complete information about a S3 Bucket, then you need to use below command. You can get important information like location, ACL details etc from this command.

[root@localhost ~]# s3cmd info s3://test-example1
s3://test-example1/ (bucket):
Location: us-east-1
Payer: BucketOwner
Expiration Rule: none
Policy: none
CORS: none
ACL: testexampleaws: FULL_CONTROL


Example 10: Check Other Options

If you want to check all the other options available with s3cmd command , then you need to use --help option as shown below.

[root@localhost ~]# s3cmd --help
Usage: s3cmd [options] COMMAND [parameters]

S3cmd is a tool for managing objects in Amazon S3 storage. It allows for
making and removing "buckets" and uploading, downloading and removing
"objects" from these buckets.

-h, --help show this help message and exit
--configure Invoke interactive (re)configuration tool. Optionally
use as '--configure s3://some-bucket' to test access
to a specific bucket instead of attempting to list
them all.


Also Read: Top 15 tools to monitor disk IO Performance

Leave a Comment