You can run the rm command to delete objects, parts, or buckets that you no longer use to avoid unnecessary storage fees.

Notice Sample command lines in this topic are based on the 64-bit Linux system. For other systems, replace ./ossutil64 in the commands with the corresponding binary name. For more information, see ossutil.

Command syntax

./ossutil64 rm oss://bucket_name[/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>]

The following table describes the parameters that you can configure when you run this command.

Parameter Description
bucket_name The name of the bucket.
prefix The resources in the bucket, such as directories or objects.
-r, --recursive If you specify this parameter, ossutil deletes all objects whose names contain the specified prefix from the bucket. If you do not specify this parameter, ossutil deletes only the specified object.
-b, --bucket Specifies the bucket to perform the command.
-m, --multipart Specifies the command to delete incomplete multipart upload tasks of objects in the bucket.
-a, --all-type Specifies the command to delete both the objects and incomplete multipart upload tasks of objects in a bucket.
-f, --force Specifies the command to forcibly run without prompting the user for confirmation.
--include Specifies the command to include all objects that meet the specified conditions.
--exclude Specifies the command to exclude all objects that do not meet the specified conditions.
--version-id Specifies the command to delete a specified version of the object. This parameter applies only to objects in buckets for which versioning is enabled or suspended.
--all-versions Specifies the command to delete all versions of a specified object. This parameter applies only to objects in buckets for which versioning is enabled or suspended. You can specify only one of the --version-id and --all-versions parameters in a single rm command.
--payer Specifies the payer of the request and traffic fees. If you want that the requester who accesses the resources to be charged for the traffic and request fees, set this parameter to requester.
--encoding-type Specifies the method used to encode the prefix specified by the object name that follows oss://bucket_name in the full object path. Valid value: url. If this parameter is not specified, the prefix is not encoded.

Delete objects

  • Examples
    • Delete a single object

      Delete an object named exampleobject.txt from a bucket named examplebucket.

      ./ossutil64 rm oss://examplebucket/exampleobject.txt
    • Delete all objects whose names contain the "test" prefix from a bucket named examplebucket.
      ./ossutil64 rm oss://examplebucket/test -r
    • Delete all objects whose names contain the ".png" suffix from a bucket named examplebucket.
      ./ossutil64 rm oss://examplebucket  --include "*.jpg" -r
    • Delete objects whose names contain the string "abc" and do not contain the ".jpg" or ".txt" suffixes from a bucket named examplebucket.
      ./ossutil64 rm oss://examplebucket  --include "*abc*" --exclude "*.jpg" --exclude "*.txt" -r
    • Delete the specified version of an object named exampleobject.txt from a versioned bucket named examplebucket.
      ./ossutil64 rm oss://examplebucket/exampleobject.txt --version-id  CAEQARiBgID8rumR2hYiIGUyOTAyZGY2MzU5MjQ5ZjlhYzQzZjNlYTAyZDE3****

      For more information about how to query all versions of an object, see ls (list buckets, objects, or parts).

    • Delete all versions of an object named exampleobject.txt from a versioned bucket named examplebucket.
      ./ossutil64 rm oss://examplebucket/exampleobject.txt --all-versions
    • Delete all versions of all objects from a versioning-enabled bucket named examplebucket.
      ./ossutil64 rm oss://examplebucket --all-versions -r
  • Returned result

    After the specified objects are deleted by using the preceding commands, an output similar to the following is returned to indicate the number of deleted objects and the time used to delete the objects:

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

Delete parts

  • Examples
    • Specify the -m parameter in the command to delete parts that are generated by the incomplete multipart upload tasks of an object named exampleobject.txt from a bucket named examplebucket.
      ./ossutil64 rm -m oss://examplebucket/exampleobject.txt
    • Specify the -m and -r parameters in the command to recursively delete parts that are generated by the incomplete multipart upload tasks of objects whose names contain the "test" prefix from a bucket named examplebucket.
      ./ossutil64 rm -m oss://examplebucket/test -r 
      Do you really mean to remove recursively multipart uploadIds of oss://examplebucket/test(y or N)? y 
    • Specify the -a and -r parameters in the command to recursively delete objects whose names contain the "src" prefix and parts that are generated by the incomplete multipart upload tasks of these objects from a bucket name examplebucket.
      ./ossutil64 rm  oss://examplebucket/src -a -r
      Do you really mean to remove recursively objects and multipart uploadIds of oss://examplebucket/src(y or N)? y
  • Returned result
    After the specified objects and parts are deleted by using the preceding commands, the following similar output is returned to indicate the number of deleted objects, the number of multipart upload tasks by which the deleted parts are generated, and the time used to delete the objects and parts:
    Succeed: Total 1 objects, 3 uploadIds. Removed 1 objects, 3 uploadIds.
    1.922915(s) elapsed

Delete buckets

  • Delete a bucket named examplebucket in which no objects or parts are stored.
    ./ossutil64 rm  oss://examplebucket -b
    Do you really mean to remove the Bucket: examplebucket(y or N)? y
    The following similar output is returned to indicate the name of the deleted bucket and the time used to delete the bucket.
    Removed Bucket: examplebucket
    2.230745(s) elapsed
  • Delete a bucket named examplebucket and all objects and parts in the bucket.
    Warning If you run the following command, all data in the specified bucket is deleted and cannot be recovered. Exercise caution when you run this command.
    ./ossutil64 rm  oss://examplebucket -b -a -r
    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

    The following similar output is returned to indicate the number of deleted objects, the number of multipart upload tasks by which the deleted parts are generated, the name of the deleted bucket, and the time used to delete the objects, parts, and bucket:

    Succeed: Total 189 objects, 37 uploadIds. Removed 189 objects, 37 uploadIds.
    Removed Bucket: examplebucket
    9.184193(s) elapsed

Common options

To use command-line tool ossutil to manage buckets that reside in different regions, you can use the -e option to use the endpoint of the specified bucket. To use command-line tool ossutil to manage buckets within multiple Alibaba Cloud accounts, you can use the -i option to use the AccessKey ID of the specified account and use the -k option to use the AccessKey secret of the specified account.

For example, you can run the following command to delete an object named exampletest.png from a bucket named testbucket, which is located in the China (Shanghai) region and owned by another Alibaba Cloud account:

./ossutil64 rm oss://testbucket/exampletest.png -e oss-cn-shanghai.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA****  -k 67DLVBkH7EamOjy2W5RVAHUY9H****