---
title: "Discussion on \"Step-By-Step: Emptying S3 Buckets and Directories Using the AWS CLI with S3 RM\" | Hashnode"
description: "Discussion on \"Step-By-Step: Emptying S3 Buckets and Directories Using the AWS CLI with S3 RM\". Master the AWS CLI to safely delete S3 buckets and folders with S3 RM, avoiding data loss and accidental file deletion."
url: "https://hashnode.com/posts/aws-s3-rm-removing-files/6423bd7544c6044aa5f7c893"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Step-By-Step: Emptying S3 Buckets and Directories Using the AWS CLI with S3 RM](https://blog.awsfundamentals.com/aws-s3-rm-removing-files?utm_source=hashnode&utm_medium=feed)

Master the AWS CLI to safely delete S3 buckets and folders with S3 RM, avoiding data loss and accidental file deletion.

Mar 29, 2023 · 7 min read · blog.awsfundamentals.com  
Updated Sep 6, 2024  
Read the article

-   [#aws](https://hashnode.com/tag/aws)
-   [#cloud-computing](https://hashnode.com/tag/cloud-computing)
-   [#devops](https://hashnode.com/tag/devops)
-   [#programming-blogs](https://hashnode.com/tag/programming-blogs)
-   [#aws-s3](https://hashnode.com/tag/aws-s3)
-   [#storage](https://hashnode.com/tag/storage)

## Written by

[Tobias Schmidt](https://hashnode.com/@tpschmidt)

@tpschmidt · Stuttgart, Germany

  
[View profile](https://hashnode.com/@tpschmidt)

Freelance Fullstack Software Engineer

Helping aspiring engineers master the cloud.

## Responses 2

Markdown supported · ⌘↵ to post

[Tobias Schmidt](https://hashnode.com/@tpschmidt)

[Jun 7, 2023](https://hashnode.com/posts/aws-s3-rm-removing-files/6423bd7544c6044aa5f7c893/comment/6480ba05dc966543c1f9e112)

Hi Shaheer!

If you want to delete a bucket with a huge number of files, there's a simple secret: create a lifecycle rule that expires all of your files.

This way you don't need a blocking command and AWS will take care of deleting the files in a background process.

This works with an unlimited number of files 💪

[Shaheer](https://hashnode.com/@BMLL)

[Jun 7, 2023](https://hashnode.com/posts/aws-s3-rm-removing-files/6423bd7544c6044aa5f7c893/comment/6480a520d78f394331bf1d6a)

Great article. I have a question regarding the speed. In the article if we compare the removing multiple files command to the removing files with a path prefix. Is there any chance one might be faster than the other? I have a gigantic bucket and even a small difference could mean a lot for me. My reasoning behind is that a prefix like "content/_.pdf" is checking for yet another additional thing hence the query should take longer if the include prefix was simply "_.pdf" Would really appreciate getting that information.
