Working with S3CMD tool on AWS S3 storage buckets

In this article we will work with s3cmd tool to manage our AWS S3 buckets. if you havent installed it go ahead and see my previous article on installing the s3cmd tool. Examples of using s3cmd tool. We will start by using the ls command option:

  • this will list all our buckets.
[root@aodba~]#  s3cmd ls
2015-11-27 05:18  s3://testbkt-aodba
We can also list the content of one specific bucket:
[root@aodba~]# s3cmd ls s3://testbkt-aodba
2016-01-31 23:29         0   s3://testbkt-aodba/bla
Create a new S3 bucket using the mb option:
[root@aodba~]# s3cmd mb s3://testbkt-aodba
Bucket 's3://testbkt-aodba/' created
Add a file to a bucket using the put option:
[root@aodba~]# s3cmd put /tmp/bla s3://testbkt-aodba
'/tmp/bla' - 's3://testbkt-aodba/bla'  [1 of 1]
 0 of 0     0% in    0s     0.00 B/s  done
'/tmp/bla' - 's3://testbkt-aodba/bla'  [1 of 1]
 0 of 0     0% in    0s     0.00 B/s  done
Add multiple files to a S3 bucket using a wildcard: 
  • we can use a * wildcard to copy file into a S3 bucket.
[root@aodbatest]# ls -1
bla
bla1
bla_1
bla_2

[root@aodbatest]# s3cmd put --force /tmp/test/*  s3://testbkt-aodba

'/tmp/test/bla' - 's3://testbkt-aodba/bla'  [1 of 4]
 0 of 0     0% in    1s     0.00 B/s  done
'/tmp/test/bla' - 's3://testbkt-aodba/bla'  [1 of 4]
 0 of 0     0% in    0s     0.00 B/s  done
'/tmp/test/bla1' - 's3://testbkt-aodba/bla1'  [2 of 4]
 0 of 0     0% in    0s     0.00 B/s  done
'/tmp/test/bla_1' - 's3://testbkt-aodba/bla_1'  [3 of 4]
 0 of 0     0% in    0s     0.00 B/s  done
'/tmp/test/bla_2' - 's3://testbkt-aodba/bla_2'  [4 of 4]
 0 of 0     0% in    0s     0.00 B/s  done

[root@aodba]# s3cmd ls s3://testbkt-aodba

2016-01-31 23:44 0 s3://testbkt-aodba/bla
2016-01-31 23:44 0 s3://testbkt-aodba/bla1
2016-01-31 23:44 0 s3://testbkt-aodba/bla_1
2016-01-31 23:44 0 s3://testbkt-aodba/bla_2
Copy a file from and S3 bucket onto your local machine using the get command option:
  • the syntax is :
 s3cmd get {bucket}/{file}   {new location}
[root@aodba~]# s3cmd get s3://testbkt-aodba/bla  /tmp/bla1
's3://testbkt-aodba/bla' - '/tmp/bla1'  [1 of 1]
's3://testbkt-aodba/bla' - '/tmp/bla1'  [1 of 1]
 0 of 0     0% in    0s     0.00 B/s  done
Copy a file from and S3 bucket onto local machine and overwrite existing one using the --force option:
[root@aodba~]# s3cmd get --force s3://testbkt-aodba/bla  /tmp/bla1

's3://testbkt-aodba/bla' - '/tmp/bla1'  [1 of 1]
's3://testbkt-aodba/bla' - '/tmp/bla1'  [1 of 1]
 0 of 0     0% in    0s     0.00 B/s  done