S3cmd is a command-line tool use for uploading, retrieving, and managing data into you s3 bucket. In this tutorial we will discuss how to install s3cmd in Linux. The main purpose of Using s3cmd is we can automate our backup task by making scripts. If you want to mount your s3 bucket with your local instance read our tutorial how to mount S3 bucket with ec2 instance.

The following step will help you to install S3cmd in Linux. Let’s do it.

Install s3cmd into Linux

S3cmd package is by default available into Ubuntu repository first update repository then you can simply install the package by executing following command.

1 2 apt - get clean apt - get update

We will install s3cmd with pip so install pip first

1 2 apt - get install python - pip pip install -- upgrade setuptools

when you will run above command it will ask for pip up gradation

1 pip install -- upgrade pip

1 2 mkdir / s3cmd cd / s3cmd

Download the package of s3cmd then unzip

we are going to download s3cmd latest package then we will unzip that package .

1 wget https : //codeload.github.com/s3tools/s3cmd/zip/master

If unzip is not installed first install that

1 2 3 apt install unzip unzip master cd s3cmd - master

when you will unzip the s3cmd package you will find there executing script just run that script your s3cmd will install.

1 python setup . py install

If you want to check that s3cms installed or not you can check it’s version.

1 s3cmd -- version

We have successfully installed s3cmd. But our task is not completed yet because our s3cmd configuration is pending. Remember one thing it’s depends on your requirement you want to configure s3cmd from root user you can do or from another user like my requirement is from linuxdady user. So I am doing from this user you can do accordingly.

1 2 3 adduser linuxdady passwd linuxdady su - linuxdady

After adding user let’s configure s3cmd. If you want to configure s3cmd you need your access key and secret key download from aws console first.

1 s3cmd configure

Enter your access key and secret key then select your region and leave rest default just hit enter. Now we have completely configured our s3cmd let’s use s3cmd

[Click & Read:– How to configure aws cli in Ubuntu]

[Click & Read:– How to convert your pem key file to ppk]

s3cmd command line explanation

let’s explation all important commands of s3cmd one by one.

1 s3cmd ls

Create bucket with s3cmd

If you want to create new bucket with s3cmd you can do that but remember on things you bucket name should be unique.

1 s3cmd mb s3 : //linux-certified

Our new bucket linux-certified has been created now check your aws console for verification.

Upload file into our bucket

We have a testing.txt file that we want to upload into our Linux-certified bucket.

1 s3cmd put testing . txt s3 : //linux-certified

Upload complete directory into our bucket

Remember one thing don’t use / after your directory name because it will upload only your directory content. LogFile is my directory name.

1 s3cmd put - r LogFile s3 : //linux-certified

List your bucket data

1 s3cmd ls s3 : //linux-certified

The above out put shows that we have on directory LogFile in our bucket and one testing.txt file. You can cross verify from aws S3 console.

Download your file and directory from bucket

1 2 s3cmd get s3 : //linux-certified/testing.txt s3cmd get - r s3 : //linux-certified/LogFile

If you want to delete your directory file for folder you can do follow the step.

1 s3cmd del s3 : //linux-certified/testing.txt

1 s3cmd del - r s3 : //linux-certified/LogFile

Remove your bucket permanently

Note down one thing If you want to delete your bucket completely then your bucket should be empty otherwise it will not delete your bucket and will prompt error “your bucket is not empty”.

1 2 3 s3cmd rb s3 : //linux-certified Output : Bucket 's3://linux-certified/' removed

Sync data between local directory and your s3 bucket

Let’s suppose I have LogFile directory into my S3 bucket and sync this directory with /tmp/data directory then follow given step

1 s3cmd sync s3 : //linux-certified/LogFile /tmp/data

Copy data from one bucket to another bucket

1 s3cmd sync s3 : //linux-certified/ s3://linuxdady/



Conclusion

In this tutorial we have install s3cmd and explained overview of S3cmd. You can perform all s3 bucket task with the help of s3cmd and you can automate your task like backup, bucket creation, bucket deletion, data upload, data download, data copy forms one bucket to another etc. etc. with the help of s3cmd and you can save your valuable time.