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
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
Bucket 's3://newspace/' created
- To List of your existing Spaces run:
- 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:
- 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
s3cmd rm s3://newspace/name/of/file
- In order to delete all files in a Space you can use
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:
- 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/
s3cmd rb s3://newspace/
You can check the full documentation about s3cmd using this link here:
Hope this helps!