Delete an S3 directory with numerous small subdirectories

0

I have an s3 directory that contains thousands of small subdirectories and I want to delete the entire directory. I have tried deleting the directory via the aws cli and aws console , but neither method works and the directory still exists.

1 Answer
1

Hello Josh,

There are two ways to accomplish what you are trying to do.

When you use AWS CLI for interacting with S3, some commands only work on single object / file unless the --recursive flag is used. S3 rm is one those commands. Please refer the documentation for more details.

Sample command will be: aws s3 rm s3://foo/bar --recursive. This command will remove the directory bar and anything inside it in the bucket foo

You can also accomplish this via the GUI. Note: This will delete the bucket altogether. If you want to delete a specific directory and everything inside it, you need to use the CLI command I listed above.

  1. Navigate to the S3 console.
  2. Select the bucket that you want to delete
  3. Click on the Empty button to empty the bucket
  4. Once the bucket is empty, you can click on Delete button to delete it Click on the Empty button
profile picture
answered 8 months ago
profile picture
EXPERT
reviewed 8 months ago
profile pictureAWS
EXPERT
reviewed 8 months ago
  • Hi, I personally use CLI with --recursive option to do this

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions