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 lists objects in the bucket, deletes them in DeleteObjects batches, and issues DeleteBucket only after the bucket is empty.

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.