DEV Community

Cover image for Amazon S3. 6 Essential CLI Commands to better manage S3 Buckets.
Souleymane. T for AWS Community Builders

Posted on

Amazon S3. 6 Essential CLI Commands to better manage S3 Buckets.

Amazon S3 or simple Simple Storage Service is a simple an object storage service offered by Amazon Web Service. With S3, the users can store various type of data (images, texts and or videos) as object in buckets.

AWS has a great web interface for creating , deleting and managing S3 buckets but it is nothing compared to the flexibility and the speed that the CLI offers

The list of CLI Command available is extensive. To lean more and go beyond what I will be converting in this blog post, click here

Bellow are 6 CLI Commands that any cloud engineer must know when dealing with Amazon S3.


1. The “mb” command Creating a new S3 Bucket.

This command is used to create new S3 Buckets. Make sure that the bucket name is unique.

Aws s3 mb myBucketName

aws s3 mb myBucketName
Enter fullscreen mode Exit fullscreen mode

2. The “ls “command.

Used to inspect buckets by listing Buckets or the content of Buckets.

aws s3 ls

aws s3 myUnikMajicBucket
Enter fullscreen mode Exit fullscreen mode

3. The “mv” command.

This is used to move things around. From local to S3, from S3 to local as well as between S3 Buckets.
People tend to get confused between the “mv” and the “cp” or copy command. mv is used to move files from location A to location B (The files no longer in location A). When “cp” is used, the file is in both location A and location B.

Move files from local to S3

aws s3 mv file1_name.txt s3://bucket-name/file2_name.txt_
Enter fullscreen mode Exit fullscreen mode

Move from S3 to local

aws s3 mv s3://bucket_name/file1_name.txt file2_name.txt
Enter fullscreen mode Exit fullscreen mode

Move files between S3 Buckets

aws s3 mv s3://bucket_name/file1_name.txt s3://bucket2_name /file2_name_2.txt  
Enter fullscreen mode Exit fullscreen mode

4. The “rb” command

This is used to delete or remove S3 Buckets. This will only work if the bucket is empty

aws s3  rb myBucket_name
Enter fullscreen mode Exit fullscreen mode

Used to force delete a bucket along with his contents

aws s3 rb Bucket_name --force  
Enter fullscreen mode Exit fullscreen mode

5. The “rm “command.

This is used to delete the content of an S3 bucket.

aws s3 rm <s3url_to_the_file>

Enter fullscreen mode Exit fullscreen mode

6. The “sync “command.

This is used to sync or update files either from local to s3, from s3 to local or between s3 buckets

aws s3 sync ./local_folder s3"//mybucket_name

Enter fullscreen mode Exit fullscreen mode

Top comments (0)