How to delete a file from S3 safely

TL;DR

Run `aws s3 rm s3://bucket/key`, or right-click → Delete in S3 Viewer. The catch: if the bucket has versioning enabled, this only adds a delete marker — the prior version is still there and still billed. To actually purge a versioned object, delete each version explicitly with its version ID. For bulk delete, S3 Viewer wraps the DeleteObjects API so you can clear up to 1,000 keys in a single call. If MFA Delete is enabled, you'll need an MFA token.

Steps

Step-by-step.

  1. 01

    In S3 Viewer: right-click → Delete

    Multi-select to bulk delete across many keys in a single DeleteObjects call (the S3 API supports up to 1,000 keys per request). The confirmation shows the count and total size before it commits.
  2. 02

    AWS CLI: aws s3 rm

    Single file or whole prefix.
    aws s3 rm s3://my-bucket/old-file.zip
    aws s3 rm s3://my-bucket/old-prefix/ --recursive
  3. 03

    Check if versioning is on first

    On a versioned bucket, aws s3 rm only adds a delete marker — the prior version is still there and still billed. Check before you delete.
    aws s3api get-bucket-versioning --bucket my-bucket
  4. 04

    List all versions if you're not sure

    Lists every version and delete marker for a key or prefix.
    aws s3api list-object-versions \
      --bucket my-bucket --prefix old-file.zip
  5. 05

    Permanently delete: remove each version

    Delete each version explicitly with its version ID. The delete marker is itself a version — delete that too if you want to fully erase the key.
    aws s3api delete-object \
      --bucket my-bucket --key old-file.zip \
      --version-id <version-id>
  6. 06

    Watch out for MFA Delete

    If MFA Delete is enabled on the bucket, deleting any version requires the bucket owner's MFA token. Plan accordingly — this is on by design for compliance buckets.
Under the hood

What's actually happening.

On a non-versioned bucket, DeleteObject removes the key immediately. On a versioned bucket, it writes a delete marker — the object becomes invisible to normal GetObject calls but every prior version is still there (and still billed). To actually purge a key, you delete each version explicitly via delete-object --version-id. S3 Viewer surfaces version state in the UI and prompts you when versioning is on, so you know whether your “delete” is a soft delete (delete marker) or a hard one. For bulk delete, S3 Viewer wraps the DeleteObjects API (up to 1,000 keys per call) — multi-select a range and clear them in one round trip.

FAQ

Common questions.

How do I delete a file from S3?

From the AWS CLI: `aws s3 rm s3://bucket/key`. From a tool: right-click → Delete in S3 Viewer (multi-select to bulk delete in a single DeleteObjects call). For prefixes from the CLI: `aws s3 rm s3://bucket/prefix --recursive`. If the bucket has versioning enabled, this only adds a delete marker — see below for permanent deletion.

Why does my deleted S3 file still appear?

Almost always versioning. On a versioned bucket, `aws s3 rm` adds a delete marker rather than purging the object — the prior versions are still there (and still billed). To fully remove the file, delete the specific version IDs with `aws s3api delete-object --version-id`.

Can I undo a delete in S3?

Only if versioning was enabled when you deleted. Remove the delete marker (or restore the prior version) to bring the object back. Without versioning, S3 deletes are permanent — there is no recycle bin.

How do I delete an entire S3 folder?

From the CLI: `aws s3 rm s3://bucket/prefix/ --recursive` lists every key under the prefix and deletes them. From S3 Viewer: select the prefix and use bulk delete. Remember S3 has no folders — you're deleting every key sharing that prefix.

How do I bulk-delete multiple S3 files?

The S3 API supports DeleteObjects (plural) — up to 1,000 keys per request. S3 Viewer wraps it in a multi-select toolbar, so shift-clicking a range and hitting delete clears the lot in one round trip. From the CLI, `aws s3 rm --recursive` with a prefix does the same thing.

What is MFA Delete in S3?

A bucket-level setting that requires the root account's MFA token to delete any version of any object. It's enabled via the AWS CLI (not the console), can only be toggled by the root account, and is the strongest accidental-deletion protection S3 offers.

Does this work with Cloudflare R2?

R2 supports DeleteObject and bulk delete the same way. R2 has its own object versioning model — check the Cloudflare docs for current behavior.
Use S3 Viewer for this

Skip the CLI. Try it in the browser.

S3 Viewer turns the steps above into a single click. Open source, self-hostable, free for personal use.