Skip to content

rm (delete)

Delete one object

To remove an object:

sh
s3m rm backup/backups/file.dat

Delete multiple objects

Delete multiple objects in one command:

sh
s3m rm backup/backups/a.txt backup/backups/b.txt

When exactly one object is provided, s3m uses DeleteObject. When 2+ object paths are provided, s3m groups them by bucket and uses DeleteObjects in batches of up to 1000 keys.

Delete an empty bucket

Delete a bucket only after removing all objects:

sh
s3m rm -b backup/empty-bucket

Recursive bucket delete

Recursively delete bucket contents in batches and then delete the bucket:

sh
s3m rm -b --recursive backup/my-bucket

--recursive is only for bucket deletion. It is version-aware: it enumerates object versions and delete markers (ListObjectVersions), removes them in DeleteObjects batches, and issues DeleteBucket only after the bucket is empty — so it can empty versioned and Object Lock buckets.

For an Object Lock bucket, retained versions are refused unless you add --bypass-governance (and COMPLIANCE retention can never be bypassed):

sh
s3m rm -b --recursive --bypass-governance backup/vault

Versioned buckets & Object Lock

On a versioned bucket (for example one created with cb --object-lock), a keyed delete does not remove data — S3 inserts a delete marker and keeps the existing versions. s3m reports this so a successful rm isn't mistaken for removal:

sh
$ s3m rm backup/vault/file.dat
backup/vault/file.dat: delete marker created (version 04db9d4f-…); existing versions are retained

Delete a specific version permanently with --version-id:

sh
s3m rm backup/vault/file.dat --version-id 4c173ee6-85a0-4da8-8884-a50d517c63fb

If that version is protected by Object Lock in GOVERNANCE mode, the delete is refused unless you also pass --bypass-governance (which requires the s3:BypassGovernanceRetention permission):

sh
s3m rm backup/vault/file.dat --version-id 4c173ee6-… --bypass-governance

COMPLIANCE-mode retention cannot be bypassed by anyone until it expires.

Retention filter

Delete only objects older than a retention threshold:

sh
s3m rm backup/backups/archive/ --older-than 90d

Shell-driven bulk delete

Prefer the built-in recursive bucket delete when the goal is to empty a bucket and then remove it:

sh
s3m rm -b --recursive backup/my-bucket

Keep the shell-driven approach for custom workflows where you explicitly want to control the object list yourself.

Example to delete all files in bucket:

sh
s3m ls backup/backups | awk '{print $NF}' | xargs -t -P4 -I '{}' s3m rm backup/backups/'{}'

In this example xargs is used with options:

  • -t Print the command line
  • -P4 Run up to 4 max-procs

Abort a multipart upload

sh
s3m rm backup/backups/file.dat --abort <upload-id>

To find the upload ID:

sh
s3m ls backup/backups --multipart

For example to abort all multipart uploads:

sh
s3m ls backup/backups --multipart | awk '{system("s3m rm backup/backups/"$5" --abort "$4);}'

Released under the BSD License.