Quick Navigation:

How to Remove Folder in AWS S3?

 

Delete an S3 directory with numerous small subdirectories

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.

- Question from repost.aws

You can store and retrieve data at any time with Amazon S3 (Simple Storage Service), a scalable object storage solution. S3 lacks actual directories and folders, in contrast to conventional file systems. Rather, it makes use of a flat namespace (bucket) that can mimic a folder organization using object keys. This implies that a folder created in S3 is basically a prefix added to the key name of the item. For example, an object with the key photos/vacation/image1.jpg appears to be inside a folder named vacation within the photos folder. However, these are just prefixes in the object's key name, and there's no actual directory structure.

Amazon S3
Amazon S3

Why Delete Folders or Files in AWS S3?

Your S3 buckets may eventually fill up with extraneous files and folders, raising storage expenses and possibly creating management issues. Deleting unwanted files or folders helps in:

  • Reducing storage costs.
  • Improving bucket organization.
  • Maintaining optimal performance.

In fact, there are multiple ways to delete folder in Amazon S3, from AWS CLI command line, GUI, to the third-party tool, just find the best way for you to clean up Amazon S3 easily.

Way 1. How to Delete Folder in S3 Bucket with AWS CLI

Strong tools for managing your S3 buckets and items are available through the AWS Command Line Interface (CLI). The aws s3 rm command can be used to delete a folder and all of its contents.

Using Recursive Option to aws s3 remove folder and Subfiles. For example, to delete a folder and all its contents, input a command using the following syntax:

aws s3 rm s3://your-bucket-name/your-folder/ --recursive

This command will remove the specified folder and all objects within it.

If you have a nested folder structure, such as photos/vacation/2025/, and want to delete everything under it, the command would be:

aws s3 rm s3://your-bucket-name/photos/vacation/2025/ --recursive

Common Mistakes When Using Recursive Deletion

  • Not using the trailing slash: Ensure you include the trailing slash (/) after the folder name to specify it's a folder.
  • Overlooking nested folders: The --recursive flag deletes all nested folders and their contents.
  • Not verifying before deletion: Always perform a dry run first to see what will be deleted.

Other Options to Delete Folders in AWS S3

AWS S3 remove all files in folder and keep folder structure: If you wish to delete all files within a folder but keep the folder structure intact, you can use the --exclude flag.

Use --dry-run: Before executing the deletion, perform a dry run to see which files will be affected.

Use --exclude and --include: To fine-tune which files to delete, use these flags to specify patterns.

For regular cleanups, consider setting up lifecycle policies in S3 to automatically delete files after a certain period.

AWS S3 Delete Folder vs AWS S3 Remove Directory

While both commands aim to delete folders, they have subtle differences.

Interchangeable Terms and What They Actually Do

  • AWS S3 delete folder: This command is often used colloquially but isn't a valid AWS CLI command. The correct command is aws s3 rm.
  • AWS S3 remove directory: Similar to the above, this is a misnomer. The correct approach is to use aws s3 rm with the --recursive flag.

Always use the correct AWS CLI command syntax:

aws s3 rm s3://your-bucket-name/your-folder/ --recursive

This ensures proper deletion of folders and their contents.

Leveraging AWS S3 Sync Delete to Keep Buckets Clean

The aws s3 sync command can be used to synchronize directories between your local machine and S3. The --delete flag ensures that files deleted locally are also removed from S3.

Syncing Local and Remote Folders with Delete Option

To sync a local directory with an S3 bucket and delete files in the bucket that are no longer present locally:

aws s3 sync /local/directory/ s3://your-bucket-name/ --delete

Pros and Cons of Using Sync for Deletion

Pros:

  • Efficiently keeps S3 in sync with local files.
  • Deletes unnecessary files from S3 automatically.

Cons:

  • Risk of accidental deletions if not used carefully.
  • Requires careful setup to ensure correct synchronization.

Way 2. AWS S3 Delete Folder with AWS Console (GUI)

Comapred with the first method, you might find it’s easier in this way, use the AWS GUI, it’s easy to remove directory in AWS S3. This will delete the bucket altogether.

1. Sign in to AWS Management Console and open to the Amazon S3 console.

2. Choose Directory buckets and 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 bucket in AWS S3.

Empty and Delete Bucket in Amazon S3
Empty and Delete Bucket in Amazon S3

Way 3. Delete Folder in AWS S3 with MultCloud

If you need to delete folders in AWS S3 easily, you can also try the powerful multiple cloud storage manager, MultCloud.

It allows you to manage all clouds in one login and manage these files as well, including deleting files from AWS S3, etc.
It supports 40+ clouds, including Google Drive, Dropbox, OneDrive, Box, Amazon S3, pCloud, MEGA, MediaFire, iCloud Drive, iCloud Photos, Wasabi, WebDAV, FTP/SFTP, ownCloud, Google Workspace, OneDrive for Business, SharePoint Online, etc.
You can easily manage files in cloud, like preview, delete, copy, move, paste, download, share, rename, cut, etc. It’s easy as ABC as on the official website.

To delete folders in AWS S3 with MultCloud, check the following steps:

1. Please create a MultCloud account and log in.

2. Click Add Cloud > Amazon S3, input the needed information to add to MultCloud.

Add Amazon S3
Add Amazon S3

3. Amazon S3 will be listed on the left side, choose the folder you need to delete, and choose Delete from the top or right-click menu.

Delete Amazon S3 Folder
Delete Amazon S3 Folder

4. In the pop up window, click Delete to confirm. Wait for a while, the selected Amazon S3 folders can be deleted quickly.

Delete Amazon S3 Folder Confirm
Delete Amazon S3 Folder Confirm
  • Smart Share: Share cloud files via public, private, or source mode.
  • One-key Move: Quick data transfer, sync, and backup among clouds.
  • Email Archive: Protect emails to other clouds or local disks.
  • Remote upload: Effectively save web files to clouds via URL.
  • Save Webpages as PDF/PNG: Keep them locally or online.
  • Instagram Download: Archive Instagram materials locally or online.
  • Easy: Access and manage all clouds in one place with one login.
  • Extensive: 30+ clouds and on-premise services are supported.

On the Bottom Line

AWS S3 remove folder can be easily archieved with multiple ways, like AWS CLI, AWS Console, and MultCloud. Compared with these methods, you might find MultCloud and AWS Console can be easily operated to delete folders in AWS Amazon S3. Besides, you can transfer files between clouds, like moving files from Amazon S3 to Sharepoint, move files from OneDrive to OneDrive for Business, etc. So, why not give it a try now?

MultCloud Logo

Manage 30+ popular clouds in one platform.

Sign up Free

100% secure

New Release

Instagram Downloader

Effortlessly download and save Instagram posts, reels, stories, and highlights to manage your favorite content anytime.

Get Started for Free