Question

How to manage DigitalOcean Spaces using s3cmd

I recently was asked if there is a way to delete a folder from a Space without accessing the Control Panel. A lot of people are using s3cmd to manage their buckets and I’ll try to give some basic examples of how you can use s3cmd to make everything easier.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
March 23, 2020
Accepted Answer

s3cmd is a popular cross-platform command-line tool for managing S3 and S3-compatible object stores.

In order to use s3cmd with DigitalOcean Spaces, you need to have:

  • s3cmd version 2.0.0+ or higher
  • An access key to your Spaces.

DigitalOcean already have a tutorial on how to install and configure s3cmd so I wont go full in details but will mention the most important things you need to do. I will recommend you to check the tutorials in order to make sure you’ve completed all the needed steps.

You can check how to setup and configure s3cmd using this tutorial

https://www.digitalocean.com/docs/spaces/resources/s3cmd

It’s important to mention that s3cmd uses the options set in its default configuration file when you run commands. The config file is a plain text file of key/value pairs which can be edited directly once it has been created.

You can use s3cmd with multiple providers, you’ll just need to have a different config file for each provider and then when you execute the commands you will specify the path to the configuration file.

If DigitalOcean is the main or only provider you’ll connect to with s3cmd and you don’t want to specify its configuration file every time you use s3cmd.

If you’re already using s3cmd with another service, you can create an alternate configuration file by adding the -c flag and supplying a filename. The configuration file will be created in the directory where you issue the command, so specify the path if you want it created elsewhere.

Here are some examples of using s3cmd with DigitalOcean Spaces


  • In order to create a new Space you can run the following command: s3cmd mb s3://newspace

  • this is successful you will receive the following outpu:

Bucket 's3://newspace/' created

  • To List of your existing Spaces run:

s3cmd ls

  • In order to list all the contents of a Space run:

s3cmd ls s3://newspace

  • In order to upload a file:

s3cmd put file.txt s3://newspace/path/

The output will be:

s3cmd put file.txt s3://newspace
upload: 'file.txt' -> 's3://newspace/file.txt'  [1 of 1]
 542770 of 542770   100% in    2s   239.63 kB/s  done

You can check this link for the other Upload options (Upload a file under a new name, Upload multiple files, Upload all files in your current directory ) with s3cmd:

https://www.digitalocean.com/docs/spaces/resources/s3cmd-usage/#upload-files-to-a-space

  • In order to download/save files you use the get attribute with s3cmd:

s3cmd get s3://newspace/path/to/file.txt

  • In order to delete a file you need to use the rm option:

s3cmd rm s3://newspace/name/of/file

  • In order to delete all files in a Space you can use rm or del

s3cmd rm s3://newspace/ --recursive --force

  • In order to delete a directory/folder:

s3cmd del s3://newspace/test

  • In order to delete a folder containing files use:

s3cmd del -r s3://newspace/test:

  • In order to list the disk usage:

s3cmd du

  • Another cool feature is to sync directories. In this way you can always make sure that you have all of your latest project files uploaded to your bucket:

s3cmd also have a ```-dry-run’‘’ which will only list the files to sync and not actually sync them. With this option you can easily check if you need to sync your files or not

s3cmd sync --dry-run test s3://newspace

if there are listed files you can remove the -dry-run and this will sync the files

  • In order to remove a bucket, first purge all the data:

s3cmd del -f -r s3://newspace/

and then:

s3cmd rb s3://newspace/

https://www.digitalocean.com/docs/spaces/resources/s3cmd-usage/

Hope this helps!

Regards, Alex

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.