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.
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!
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.
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:
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
s3cmd ls
s3cmd ls s3://newspace
s3cmd put file.txt s3://newspace/path/
The output will be:
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
get
attribute with s3cmd:s3cmd get s3://newspace/path/to/file.txt
rm
option:s3cmd rm s3://newspace/name/of/file
rm
ordel
s3cmd rm s3://newspace/ --recursive --force
s3cmd del s3://newspace/test
s3cmd del -r s3://newspace/test:
s3cmd du
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 filess3cmd del -f -r s3://newspace/
and then:
s3cmd rb s3://newspace/
You can check the full documentation about s3cmd using this link here:
https://www.digitalocean.com/docs/spaces/resources/s3cmd-usage/
Hope this helps!
Regards, Alex