Skip to content

Instantly share code, notes, and snippets.

@leommoore
Last active May 25, 2022 11:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save leommoore/947124c7ece2c5ddf2cf to your computer and use it in GitHub Desktop.
Save leommoore/947124c7ece2c5ddf2cf to your computer and use it in GitHub Desktop.
S3Cmd

S3Cmd - S3 Command Line Tools

S3cmd is a free command line tool and client for uploading, retrieving and managing data in Amazon S3 and other cloud storage service providers that use the S3 protocol, such as Google Cloud Storage or DreamHost DreamObjects. It is best suited for power users who are familiar with command line programs. It is also ideal for batch scripts and automated backup to S3, triggered from cron, etc.

S3cmd is written in Python. It's an open source project available under GNU Public License v2 (GPLv2) and is free for both commercial and private use. You will only have to pay Amazon for using their storage.

It is available on http://s3tools.org/s3cmd

Installing S3Cmd

To install on Ubuntu use:

sudo apt-get install s3cmd

On Windows download go to http://s3tools.org/download and download the zip file straight from https://github.com/s3tools/s3cmd/archive/master.zip. Unzip this file into a suitable location and ensure that you have Python 2.7 installed. You may want to add the S3Cmd and Python locations to your path.

##Using S3Cmd Note: to use S3 in Windows you have to put python in front of the command so that it uses python to interperet the command. For example to get a file from S3:

python s3cmd get s3://recinal.receipts/15767-109yhsz.jpg

##C onfigure To configure S3Cmd use:

s3cmd --configure

Regex

Yo can use regular expressions with s3cmd. For example to exclude log files from a command you could use --rexclude=.*\. to exclude all files with a .log extension.

Commands

To make a bucket

s3cmd mb s3://newbucket

To list the contents of a bucket

s3cmd ls s3://newbucket s3cmd ls s3://newbucket/mysubdirectory

To put a file in a bucket

s3cmd put textfile.txt s3://newbucket

To Get a file

s3cmd get s3://newbucket/textfile.txt

To Delete a file

s3cmd del s3://newbucket/textfile.txt

To view the space taken up by each bucket

s3cmd du

To copy a file to a different bucket

s3cmd cp s3://newbucket/textfile.txt s3://differentbucket/textfile.txt

To move a file to a different bucket

s3cmd mv s3://newbucket/textfile.txt s3://differentbucket/textfile.txt

Note: you can also use this to rename a file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment