Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security, Veeam & DevOps

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form

How to delete AWS S3 Bucket and Objects via  AWS CLI from Linux

Posted on 19/01/202315/08/2026 Imoh Etuk By Imoh Etuk No Comments on How to delete AWS S3 Bucket and Objects via  AWS CLI from Linux
  1. Home
  2. AWS/Azure/OpenShift
  3. How to delete AWS S3 Bucket and Objects via  AWS CLI from Linux
S3-Bucket-1
S3 Buckets

The Amazon Simple Storage Service (Amazon S3) is a cloud hosting service that offers industry-leading performance, security, and scalability. Users and organizations of all sizes can use Amazon S3 to safeguard and store data for a variety of applications, including websites, mobile applications, data lakes, backups and restores, archives, enterprise applications, IoT devices, and big data analytics. Amazon S3 can be used to optimize, organize, and configure access to your data based on your specific business, organizational, and compliance requirements. In this guide, you will learn how to delete AWS S3 Bucket and Objects via  AWS CLI from Linux.

To learn how to interact with the AWS S3 bucket using AWS CLI on Windows, refer to How to Programmatically Assess AWS Management Console and Create Resources from the Command-line using AWS CLI in Windows, Understanding AWS CLI: How to configure Command Line Interface [Part 2], How to add an EBS volume to AWS EC2 via the AWS Console and CLI

Amazon S3 is an object cloud storage service that stores data in buckets as objects. A file and any metadata that describes the file are considered objects. AWS S3 bucket is a container that holds objects. A bucket is a storage location for items in Amazon S3. A bucket can hold any number of items, and your account can hold up to 100 buckets.

Delete AWS S3 Bucket and Objects via  AWS CLI from Linux

In order to fulfil this goal of this topic, we will have to define the core concept of the management tool we will be using for this task.

AWS Command Line Interface (AWS CLI)

The AWS Command Line Interface (AWS CLI) is a centralized management tool for your AWS services. You can control multiple AWS services from the command line and automate them using scripts with just one tool to install and set up. It is a free and open-source tool for interacting with AWS services via command-line shell commands.

With minimal configuration, the AWS CLI allows you to start running commands that use functionality similar to that of the browser-based AWS Management Console from the command prompt in your terminal program.

In this post, I will take you through the following: installing the AWS CLI package on a local system, assigning permissions to the user, generating and configuring the access key ID and secret access key, and deleting the S3 bucket and its objects using the AWS CLI. We will carry out all the interactions with the AWS S3 bucket directly from the Linux terminal.

Prerequisite for Installing AWS CLI

To follow along in this write-up, you need to have the following:

  1. Install AWS CLI on your PC, see a related guide  AWS Command-Line Interface: How to configure AWS CLI [Part 1] 
  2. Active AWS Subscription
  3. Have the IAM Permission to create and manage S3 Bucket

Installing AWS CLI package on a local system

To install the AWS CLI package on your system, run the below commands to update your system packages and then download the AWS CLI.

sudo apt update -y
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Install-AWS-CLI
Downloading AWS CLI

After downloading the awsscli, run the sudo apt install unzip and unzip awscliv2.zip to you to install unzip and use it to unzip the file.

Install-Unzip-command-
Installing Unzip package and unzipping the awscli file

Now, install the awscli by running:

sudo ./aws/install

Please note the directory where you unzip the file to. Here the file was extracted to the AWS folder.

Install-CLI
Installing AWS CLI

Assign permissions to the user

AWS offers IAM roles and policies to limit user access to various AWS resources. Your user account must have specific permissions before performing any action on AWS. This section will grant the user account the necessary permissions to perform various tasks on S3. To begin, log in to the AWS management console and navigate to the IAM service.

Creating-an-IAM-User
Accessing IAM Portal

While on the Identity and Access Management (IAM) portal, click on User

Adding-an-IAM-User
Adding a User

Specify the username

Specify-the-user-name

Add User to a Group

Add-user-to-group
Adding a User to a group

Assign permission to the user to be able to manage S3 Bucket by clicking on the Add inline policy

Assign-permission
Assigning permission to the User

Search for and select S3 from the list of services

S3-Bucket-2
Attaching the appropriate permissions

Generating and configuring the access key ID and secret access key

You need some credentials to authorize your requests in order to use the AWS command-line interface on your local computer. AWS access key ID and secret access key are used as credentials for the AWS command-line interface. We will create and set up these credentials on our local system in this section.

To generate and configure the access key ID and secret access key, go to the Users section of the IAM console, then click on the username.

Clicking-on-the-user-name
Assessing the User

Click the Create access key button after scrolling down to the Access keys section.

Click-on-Create-access-key
Creating Access Key

Choose how you want to use the Access key

Choose-access-key-best-practices
Choosing the best practice for your access key

Download the CSV file containing the access key ID and secret access Key

Retrieve-the-access-key
Download the Acces key

Use the terminal on your local system to configure the AWS command-line credentials after they have been generated and downloaded. To configure the credentials, use the aws configure command and supply the access key ID and secret access key, set your default region, and default output format.

AWS-Configure-Access-Key
Configuring the AWS Access Key ID and Secret Access Key

We have two buckets on our account.

List S3 Bucket Objects with CLI

Let’s list the objects/files in one of the S3 bucket using the below command:

aws s3 ls <bucket-name>
List-bucket-objects
Listing S3 Bucket Objects

There are about six objects in one of the buckets.

Deleting S3 Bucket Object using AWS CLI

To empty all the objects in your S3 Buckets, run:

aws s3 rm s3://<bucket-name> --recursive
Deleting-S3-bucket-objects
Deleting S3 Bucket Objects

Verify that the objects have been deleted by running:

aws s3 ls <bucket-name>
Verify-the-objects-have-been-deleted
Verifying deleted S3 Bucket Objects

Deleting S3 Bucket

Now that we have emptied the S3 Bucket, let’s proceed to delete the entire bucket using the below command:

aws s3 r s3://<bucket-name>
Removing-bucket
Deleting S3 Bucket

Congratulations! You have learned how to delete AWS S3 Bucket and Objects via  AWS CLI from Linux. In conclusion, AWS CLI is a powerful tool that you can use to centrally control and manage your resources in your AWS environment.

In summary, we discussed how to install and configure the AWS CLI package in your Local PC’s terminal and directly interacted with AWS S3 buckets and their objects. You also got to understand how to create an IAM User and assign permission to them and finally learnt how to delete S3 bucket objects and the entire S3 bucket.

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
AWS/Azure/OpenShift, Linux Tags:AWS, AWS CLI, S3 Bucket

Post navigation

Previous Post: Install Ubuntu 20.04 LTS on Windows via WSL
Next Post: Enable BitLocker AES-XTX 256 Encryption

Related Posts

  • AADSTS50020 User from Identity Provider does not exist in Tenant
    AADSTS50020: User from Identity Provider does not exist in Tenant AWS/Azure/OpenShift
  • Package1
    Install Synaptic Package Manager: Handle packages in Ubuntu Linux
  • HAProxy
    Deploying a load balancer from scratch and adding backend servers Linux
  • Create a User and Custom Domain in Entra ID
    How to Create a User and Custom Domain in Entra ID AWS/Azure/OpenShift
  • fba7f screenshot 2019 04 15 at 18.33.30
    File System Overview: How to decide on the right File System to use for your USB Linux
  • FEATUREDC
    How to create Confidential VMs in Azure AWS/Azure/OpenShift

More Related Articles

Set a Resource Delete Lock How to Add a Delete Lock on Azure Resources AWS/Azure/OpenShift
Azure Backup Copy 1 How to Delete Backup Job in Recovery Services Vault AWS/Azure/OpenShift
AADSTS900144 Fix AADSTS900144: The request body must contain the parameter Linux
azure file share feature image Deploy Legacy App to Azure Fileshare AWS/Azure/OpenShift
Screenshot 2022 03 15 at 10.05.53 VMware Workstation states: What are the differences between Suspend, Power Off, and Run in Background Linux
FEATUREIMAGE How to work with Azure Cognitive Service AWS/Azure/OpenShift

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

vexpert-badge-stars-5

Virtual Background

VEEAMLEGEND

Categories

Top 30 Sysadmin blog

veeaam100

Veeam Vanguard

  • reliablee
    How to use the Reliability Monitor in Windows Windows
  • BitLocker removal on Windows Server
    How to correctly disable BitLocker on Windows Server Windows Server
  • azure active director
    AD Connect Error: The Synchronisation service scheduler is currently synchronization and the configuration change cannot be made at this time AWS/Azure/OpenShift
  • powershell01
    How to create a KDS root key using PowerShell Scripts
  • original
    Windows Deployment Services: WDSUTIL CommandLine Options on Windows Server 2019 Windows Server
  • article 1280x720.192a2586 1 1
    No valid offer received: WDS PXE-E16 error when booting clients Windows Server
  • Screenshot 2021 03 29 at 01.56.17
    How to prevent VLC player from reverting to the native video size on Mac Mac
  • Security updated something did not go well as planned
    Something did not go well as planned: Windows Security update fails to install Windows

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,746 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Contact
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon
  • Bsky

Tags

Active Directory Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2026 TechDirectArchive

Loading Comments...

You must be logged in to post a comment.