All Products
Search
Document Center

Object Storage Service:rm

Last Updated:Feb 27, 2026

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>]
OptionDescription
bucketnameThe name of the bucket.
prefixThe prefix in resource names, such as directories or objects.
-r, --recursiveRecursively deletes all objects whose names contain the specified prefix. Without this option, only the specified object is deleted.
-b, --bucketDeletes the bucket itself. Required only for bucket deletion.
-m, --multipartTargets incomplete multipart upload tasks in the bucket.
-a, --all-typeTargets both objects and data from incomplete multipart upload tasks.
-f, --forceSkips the confirmation prompt.
--includeIncludes objects that match the specified conditions. For details, see Options --include and --exclude.
--excludeExcludes objects that match the specified conditions. For details, see Options --include and --exclude.
--version-idThe version ID of the object. Applies only to versioning-enabled or versioning-suspended buckets.
--all-versionsTargets all versions of objects. Applies only to versioning-enabled or versioning-suspended buckets. Mutually exclusive with --version-id.
--payerThe payer of request and traffic fees. Set to requester for pay-by-requester mode.
--encoding-typeThe 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.

OperationRequired permissions
Delete a single objectoss:DeleteObject
Delete all objects in a directoryoss:DeleteObject, oss:ListObjects
Delete a specific object versionoss:DeleteObjectVersion
Delete all object versions in a bucketoss:ListObjectVersions, oss:DeleteObjectVersion
Delete all object versions in a directoryoss:DeleteObjectVersion, oss:ListObjects
Delete partsoss:ListMultipartUploads, oss:AbortMultipartUpload
Delete all objects and parts in a bucketoss:ListMultipartUploads, oss:AbortMultipartUpload, oss:ListObjects, oss:DeleteObject
Delete a bucketoss:DeleteBucket

Delete objects

Warning

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.txt

Delete objects by prefix

Delete all objects whose names start with test from the examplebucket bucket:

ossutil rm oss://examplebucket/test -r

A successful response shows the number of deleted objects and elapsed time:

Succeed: Total 8 objects. Removed 8 objects.
0.106852(s) elapsed

Delete objects by pattern

Warning

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" -r

Example 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" -r

Delete 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-versions

Example 3: Delete all versions of all objects

ossutil rm oss://examplebucket --all-versions -r

Delete 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.txt

Example 2: Delete parts by prefix

Recursively delete parts from incomplete multipart uploads whose object names start with test:

ossutil rm -m oss://examplebucket/test -r

Interactive prompt:

Do you really mean to remove recursively multipart uploadIds of oss://examplebucket/test(y or N)? y

Example 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 -r

Interactive prompt:

Do you really mean to remove recursively objects and multipart uploadIds of oss://examplebucket/src(y or N)? y

Output:

Succeed: Total 1 objects, 3 uploadIds. Removed 1 objects, 3 uploadIds.
1.922915(s) elapsed

Delete a bucket

Delete an empty bucket

Delete the examplebucket bucket that contains no objects or parts:

ossutil rm oss://examplebucket -b

Interactive prompt and output:

Do you really mean to remove the Bucket: examplebucket(y or N)? y
Removed Bucket: examplebucket
2.230745(s) elapsed

Delete a bucket and all its contents

Warning

This operation deletes all data in the bucket. Deleted data cannot be recovered.

ossutil rm oss://examplebucket -b -a -r

Interactive 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) elapsed

Common options

To operate on a bucket in a different region or owned by a different Alibaba Cloud account, use the following options:

OptionDescription
-eThe endpoint of the region where the bucket is located.
-iThe AccessKey ID of the target account.
-kThe 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:

PlaceholderDescription
<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.