Delete objects, incomplete multipart upload parts, or buckets to avoid unnecessary charges.
Usage notes
For ossutil 1.6.16 and later, use ossutil as the binary name directly. For earlier versions, update the binary name based on your operating system. For details, see ossutil command reference.
Command syntax
ossutil rm oss://bucketname[/prefix]
[-r, --recursive]
[-b, --bucket]
[-m, --multipart]
[-a, --all-type]
[-f, --force]
[--include <value>]
[--exclude <value>]
[--version-id <value>]
[--all-versions]
[--payer <value>]
[--encoding-type <value>]| Option | Description |
|---|---|
bucketname | The name of the bucket. |
prefix | The prefix in resource names, such as directories or objects. |
-r, --recursive | Recursively deletes all objects whose names contain the specified prefix. Without this option, only the specified object is deleted. |
-b, --bucket | Deletes the bucket itself. Required only for bucket deletion. |
-m, --multipart | Targets incomplete multipart upload tasks in the bucket. |
-a, --all-type | Targets both objects and data from incomplete multipart upload tasks. |
-f, --force | Skips the confirmation prompt. |
--include | Includes objects that match the specified conditions. For details, see Options --include and --exclude. |
--exclude | Excludes objects that match the specified conditions. For details, see Options --include and --exclude. |
--version-id | The version ID of the object. Applies only to versioning-enabled or versioning-suspended buckets. |
--all-versions | Targets all versions of objects. Applies only to versioning-enabled or versioning-suspended buckets. Mutually exclusive with --version-id. |
--payer | The payer of request and traffic fees. Set to requester for pay-by-requester mode. |
--encoding-type | The encoding type for the prefix after oss://bucket_name. Valid value: url. If not specified, the prefix is not encoded. |
Required permissions
Each operation requires a specific set of permissions. Grant only the permissions needed for the intended operation.
| Operation | Required permissions |
|---|---|
| Delete a single object | oss:DeleteObject |
| Delete all objects in a directory | oss:DeleteObject, oss:ListObjects |
| Delete a specific object version | oss:DeleteObjectVersion |
| Delete all object versions in a bucket | oss:ListObjectVersions, oss:DeleteObjectVersion |
| Delete all object versions in a directory | oss:DeleteObjectVersion, oss:ListObjects |
| Delete parts | oss:ListMultipartUploads, oss:AbortMultipartUpload |
| Delete all objects and parts in a bucket | oss:ListMultipartUploads, oss:AbortMultipartUpload, oss:ListObjects, oss:DeleteObject |
| Delete a bucket | oss:DeleteBucket |
Delete objects
Deleted objects cannot be recovered. If versioning is enabled on the bucket, deleting an object creates a delete marker, and previous versions remain accessible. For non-versioned buckets, deletion is permanent.
Deleting objects (with or without -r) calls the ListObjects (GetBucket) and DeleteObject API operations. These calls are billed as PUT requests. For details, see API operation calling fees.
Delete a single object
Delete exampleobject.txt from the examplebucket bucket:
ossutil rm oss://examplebucket/exampleobject.txtDelete objects by prefix
Delete all objects whose names start with test from the examplebucket bucket:
ossutil rm oss://examplebucket/test -rA successful response shows the number of deleted objects and elapsed time:
Succeed: Total 8 objects. Removed 8 objects.
0.106852(s) elapsedDelete objects by pattern
Misconfigured --include and --exclude conditions can cause accidental deletions. Before running rm, preview matching objects with ossutil ls using the same prefix and filter options.
Multiple conditions are evaluated left to right. Specify --include before --exclude for predictable results.
Example 1: Delete all .png files
Delete all objects with the .png suffix from the examplebucket bucket:
ossutil rm oss://examplebucket --include "*.png" -rExample 2: Delete objects matching include/exclude patterns
Delete objects containing abc in their names, excluding .jpg and .txt files, from the examplebucket bucket:
ossutil rm oss://examplebucket --include "*abc*" --exclude "*.jpg" --exclude "*.txt" -rDelete versioned objects
The following examples apply to versioning-enabled or versioning-suspended buckets.
Example 1: Delete a specific version
Delete a specific version of exampleobject.txt from the examplebucket bucket:
ossutil rm oss://examplebucket/exampleobject.txt --version-id CAEQARiBgID8rumR2hYiIGUyOTAyZGY2MzU5MjQ5ZjlhYzQzZjNlYTAyZDE3****To list all versions of an object, see ls.
Example 2: Delete all versions of a single object
ossutil rm oss://examplebucket/exampleobject.txt --all-versionsExample 3: Delete all versions of all objects
ossutil rm oss://examplebucket --all-versions -rDelete parts
Deleting parts calls the ListMultipartUploads, ListParts, and AbortMultipartUpload API operations. ListMultipartUploads and ListParts calls are billed as GET requests. AbortMultipartUpload calls are billed as PUT requests. For details, see API operation calling fees.
Example 1: Delete parts for a single object
Delete parts from an incomplete multipart upload of exampleobject.txt in the examplebucket bucket:
ossutil rm -m oss://examplebucket/exampleobject.txtExample 2: Delete parts by prefix
Recursively delete parts from incomplete multipart uploads whose object names start with test:
ossutil rm -m oss://examplebucket/test -rInteractive prompt:
Do you really mean to remove recursively multipart uploadIds of oss://examplebucket/test(y or N)? yExample 3: Delete objects and parts together
Recursively delete objects whose names start with src and their associated incomplete multipart upload parts:
ossutil rm oss://examplebucket/src -a -rInteractive prompt:
Do you really mean to remove recursively objects and multipart uploadIds of oss://examplebucket/src(y or N)? yOutput:
Succeed: Total 1 objects, 3 uploadIds. Removed 1 objects, 3 uploadIds.
1.922915(s) elapsedDelete a bucket
Delete an empty bucket
Delete the examplebucket bucket that contains no objects or parts:
ossutil rm oss://examplebucket -bInteractive prompt and output:
Do you really mean to remove the Bucket: examplebucket(y or N)? y
Removed Bucket: examplebucket
2.230745(s) elapsedDelete a bucket and all its contents
This operation deletes all data in the bucket. Deleted data cannot be recovered.
ossutil rm oss://examplebucket -b -a -rInteractive prompts and output:
Do you really mean to remove recursively objects and multipart uploadIds of oss://examplebucket(y or N)? y
Do you really mean to remove the Bucket: examplebucket(y or N)? y
Succeed: Total 189 objects, 37 uploadIds. Removed 189 objects, 37 uploadIds.
Removed Bucket: examplebucket
9.184193(s) elapsedCommon options
To operate on a bucket in a different region or owned by a different Alibaba Cloud account, use the following options:
| Option | Description |
|---|---|
-e | The endpoint of the region where the bucket is located. |
-i | The AccessKey ID of the target account. |
-k | The AccessKey secret of the target account. |
Delete exampletest.png from testbucket in the China (Shanghai) region, owned by a different account:
ossutil rm oss://testbucket/exampletest.png -e oss-cn-shanghai.aliyuncs.com -i <your-access-key-id> -k <your-access-key-secret>Replace the following placeholders with actual values:
| Placeholder | Description |
|---|---|
<your-access-key-id> | The AccessKey ID of the target Alibaba Cloud account |
<your-access-key-secret> | The AccessKey secret of the target Alibaba Cloud account |
For a complete list of common options, see Common options.