What Is S3cmd in Linux?
S3cmd is a command line tool that is responsible for retrieving and uploading the data as well as maintaining the data in various S3 cloud storage such as Amazon S3, Google cloud storage, etc. It is a user-friendly command line that is easy for beginners to learn. It can also be used as a powerful tool for advanced users. It is a command line that is used to execute the tasks such as creating or removing buckets, copying files from or to simple storage services such as Amazon S3, listing the objects, etc.
How to Use S3cmd to Manage the Object Storage
As mentioned before, S3cmd is an open-source command line that can be used for a variety of purposes such as uploading the data or managing the data in S3 amenable object storage. It is a powerful command line that is good for automation.
Due to S3cmd ease of use, it is a good choice to manage the object storage in a server. S3cmd is built to connect to single storage at one time by creating the configuration files. These configuration files contain all the important and necessary keys and details that are needed to manage the buckets and their files on the object storage.
After the S3cmd is configured, commands can be used to see how it works. Note that all the data is organized as buckets in the object storage. Now, we move onto the S3cmd commands and their examples.
S3cmd Commands
S3cmd command line can perform and execute the following actions by following the commands. Here are some actions that are performed when executing the given commands. We will look at some of the S3cmd command examples and learn how to get an access to the files from S3 storage using these s3cmd command line tools. These commands can also help to download the files or upload them from the storage regularly or in intervals if the commands are programmed earlier.
How to Create a New Bucket
When we want to create an S3 Bucket, the following command is to be used. Looking at the command, we have to take note that the bucket name starts with the s3:// prefix. If this is not applied, you will get an error:
See the following output when we run the given command:
A new bucket named “newBucket” is created in the s3 directory. The s3cmd command records the bucket creation time and date which can be seen when listing the buckets.
How to List Down All Buckets
To view all the buckets in your account as well as the files in a list, the command that should be used is:
This command’s output is detailed based on the number of buckets and their files or content. Refer to the output of the following command:
Since we only have one bucket which is the “newBucket” in the s3 directory, it is listed by the s3cmd command with the respective time and date.
How to Put Files Into the Bucket
Now that we created a bucket, let us upload a file in the bucket using the “put” command. We upload the “file.txt” file in the s3 bucket with the following command:
Here is the actual command:
Since the file is empty, it will be uploaded quickly using the put command. The following is the output from the executed command:
How to List a Bucket
To list the buckets and all the files in them, the following command needs to be executed. Here is the actual command:
The output is as follows:
How to Get Files from a Bucket
To get or move the files to the local system from the bucket, the following command line is used. See the actual command in the following:
The output from the command used is as follows:
How to Delete a File from a Bucket
Another example can be the deletion of the file from the bucket. To delete a file from a bucket, here is the required command that should be executed:
Here, we delete the files from the bucket. The following is the output from the command:
How to Delete a Bucket
To delete a Bucket, the first thing that you should do is to remove all the files from that bucket and empty it. Otherwise, you will get an error that may say something along the line of “the bucket you tried to delete is not empty”. The following command is used to delete a bucket:
Check the sample command in the following:
See the output for the given command. Here, you can see that the bucket is deleted.
Conclusion
This article provides a quick overview of s3cmd commands in the Linux operating system. The s3cmd command in the Linux operating system is a command line tool that is used to retrieve, move, or upload the data as well as maintain the data in various S3 cloud storage such as Amazon S3, Google cloud storage, etc. Since this article is designed to demonstrate the s3cmd command, we learned what s3cmd is, how to manage the storage using S3cmd, and what are some of the S3cmd commands. Many s3cmd command examples are given for a better understanding of the s3cmd command line. To clear your concepts, run the examples provided and see the results.