rm (delete)
Delete one object
To remove an object:
s3m rm backup/backups/file.datDelete multiple objects
Delete multiple objects in one command:
s3m rm backup/backups/a.txt backup/backups/b.txtWhen 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 all objects under a prefix
Delete every object whose key starts with a literal prefix, while keeping the bucket itself:
# Delete one exact object (a key ending in "/" is deleted as that exact key)
s3m rm backup/my-bucket/path/file.txt
# Delete every object whose key starts with the literal prefix
s3m rm backup/my-bucket/integration/18/ --recursive- Literal S3 key prefix: The target key is matched literally, not as a filesystem directory.
integration/18/matchesintegration/18/a,integration/18/x/b, and a key equal tointegration/18/, but notintegration/18,integration/180/a, orintegration/18-other/a. No globbing or path normalization is performed. - Trailing slash warning: Keep the trailing slash (
/). Without it,integration/18would also matchintegration/180/...;s3mprints a warning onstderrwhen the trailing slash is missing (the deletion still runs). - Bucket is preserved: Without
--bucket(-b), running--recursivenever deletes the bucket. - Safety guards:
- The prefix must not be empty (
s3m rm backup/my-bucket --recursiveis rejected; use-b --recursiveto delete a whole bucket). --bucketcannot be combined with an object key or prefix.--recursivetakes exactly one target and cannot be combined with--older-than,--version-id, or--abort.
- The prefix must not be empty (
- No-op on empty prefixes: A prefix with no matching objects is a successful no-op (exits
0and reports nothing was deleted). - Batching and errors: Objects are listed via
ListObjectsV2and deleted page by page viaDeleteObjects(at most 1,000 keys per request). Any listing error, request error, or per-object error (e.g. Object Lock) halts the command with a non-zero exit status and reports the count of objects already removed. - Versioned buckets: Current objects are deleted without a version ID, so S3 creates delete markers and retains earlier versions (the command reports the number of delete markers created). Object Lock protections apply as usual (
--bypass-governancecan be passed to bypassGOVERNANCEretention).
Delete an empty bucket
Delete a bucket only after removing all objects:
s3m rm -b backup/empty-bucketSafety check
--bucket (-b) deletes a whole bucket and cannot be combined with an object key or prefix (e.g. s3m rm -b backup/bucket/file.txt or s3m rm -b -r backup/bucket/path/ is rejected with an error; previously the key was silently ignored and the bucket was deleted).
Recursive bucket delete
Recursively delete all objects and versions in the bucket in batches, then delete the bucket itself:
s3m rm -b --recursive backup/my-bucketWith --bucket (-b), --recursive is version-aware: it enumerates all object versions and delete markers (ListObjectVersions), removes them in DeleteObjects batches of up to 1,000 keys, and issues DeleteBucket once empty — completely wiping and deleting the bucket.
For an Object Lock bucket, retained versions are refused unless you add --bypass-governance (and COMPLIANCE retention can never be bypassed):
s3m rm -b --recursive --bypass-governance backup/vaultVersioned 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:
$ s3m rm backup/vault/file.dat
backup/vault/file.dat: delete marker created (version 04db9d4f-…); existing versions are retainedDelete a specific version permanently with --version-id:
s3m rm backup/vault/file.dat --version-id 4c173ee6-85a0-4da8-8884-a50d517c63fbIf 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):
s3m rm backup/vault/file.dat --version-id 4c173ee6-… --bypass-governanceCOMPLIANCE-mode retention cannot be bypassed by anyone until it expires.
Retention filter
Delete only objects older than a retention threshold:
s3m rm backup/backups/archive/ --older-than 90dShell-driven bulk delete
Prefer the built-in recursive bucket delete when the goal is to empty a bucket and then remove it:
s3m rm -b --recursive backup/my-bucketKeep the shell-driven approach for custom workflows where you explicitly want to control the object list yourself.
Example to delete all files in bucket:
s3m ls backup/backups | awk '{print $NF}' | xargs -t -P4 -I '{}' s3m rm backup/backups/'{}'In this example xargs is used with options:
-tPrint the command line-P4Run up to 4 max-procs
Abort a multipart upload
s3m rm backup/backups/file.dat --abort <upload-id>To find the upload ID:
s3m ls backup/backups --multipartFor example to abort all multipart uploads:
s3m ls backup/backups --multipart | awk '{system("s3m rm backup/backups/"$5" --abort "$4);}'
