S3cmd is written in Python, so it is just about supported in all operating systems, as long as Python is installed.

Installation

S3cmd is found in most Linux repositories. In Debian/Ubuntu, or any other apt-based distro, you can install S3cmd with the command: For Fedora, Centos, or any other yum-based distro: Alternatively, you can download the source code, unzip the package and run the installer:

Getting Started

To get started, open the terminal and type: It will first prompt you to enter your Access and Secret keys.

Next, you have to enter an encryption key and the path to the GPG program.

Once you have configured and tested the settings, you can proceed to use S3cmd. If you need to change the settings, you can either edit the .s3cfg file in your Home directory, or run the s3cmd –configure command again.

Usage

First, to view the buckets in your S3 account, you can use the ls command.

To create a bucket, use the mb command: Note that you will need to prefix the bucket name with “s3://”

To list the content in a bucket, use the ls command together with the bucket name. For example:

Uploading file to bucket

The easiest way to upload a file via S3cmd is with the put command. For example: In addition, you can use the –encrypt parameter to encrypt the file before uploading to S3. The default permission for the put command is private, which means the file can only be viewed by you. If you need the file to be publicly accessible, you can add the parameter –acl-public For more granular control, use the –acl-grant=PERMISSION:EMAIL or USER_CANONICAL_ID parameter. For example: The “PERMISSION” can be “read,” “write,” “read_acp,” “write_acp,” “full_control,” “all.”

Retrieving files from bucket

To retrieve a file, use the get command. To download all files in the bucket, simply append the –recursive parameter.

Deleting files from bucket

The delete command for s3cmd is simply del. For example: You can also use the –recursive parameter to delete all files in the bucket. For more S3cmd commands, check out its usage guide here.

Advanced Usage: Synchronize a folder to S3

Let’s say you store all your important files in a folder and you want it to be synced to S3. S3cmd comes with a sync command that can synchronize the local folder to the remote destination. All you have to do is to create a cronjob to run the sync command regularly.

  1. Open the crontab.
  2. Add the following line to the end of the crontab. Save and exit the crontab. That’s it. Your system will now sync the secret folder to S3 every 5 minutes. You can change the value to run the sync command at your preferred interval. Every file you removed from the secret folder will be removed from S3 too.

Conclusion