This topic describes how to run the rm command to delete objects, parts, or buckets that you no longer need to avoid unnecessary charges.

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://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>]

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

Parameter Description
bucketname The name of the bucket in which the objects you want to delete are stored.
prefix The resources in the bucket whose names contain the specified prefix, 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 specified objects.
-b, --bucket Specifies that the command is run to delete a bucket. This option can be configured only when you run the command to delete a bucket.
-m, --multipart Specifies that the operation is performed on the incomplete multipart upload tasks in a bucket.
-a, --all-type Specifies that the operation is performed on the objects and incomplete multipart upload tasks in the bucket.
-f, --force Specifies the operation to forcefully perform without prompts for confirmation.
--include Specifies that the command applies to all objects that meet specified conditions.
--exclude Specifies that the command applies to all objects that do not meet specified conditions.
--version-id The version ID of the object that you want to delete. This option applies only to objects in buckets for which versioning is enabled or suspended.
--all-versions Specifies all versions of objects. This option 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 options in a single rm command.
--payer Specifies the payer of the traffic and request fees charged when the command is run. If you want the requester who accesses the resources in the specified path to pay for the traffic and request fees, set this option to requester.
--encoding-type 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 you do not specify this option, the prefix is not encoded.

Delete objects

Warning Objects cannot be recovered after they are deleted. Exercise caution when you perform this operation.
  • 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 "*.png" -r
    • Delete objects whose names contain the string "abc" and do not contain the ".jpg" or ".txt" suffix 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 Is.

    • 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 versioned bucket named examplebucket.
      ./ossutil64 rm oss://examplebucket --all-versions -r
  • Command output

    After the specified objects are deleted by running the preceding commands, a similar output is displayed, which indicates 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 option in the command to delete parts that are generated by 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 options 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 options 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
  • Command output
    After the specified objects and parts are deleted by running the preceding commands, a similar output is displayed, which indicates 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 the examplebucket bucket that contains no objects or parts.
    ./ossutil64 rm  oss://examplebucket -b
    Do you really mean to remove the Bucket: examplebucket(y or N)? y
    A similar output is displayed, which indicates 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 bucket is deleted and deleted data cannot be recovered. Exercise caution when you perform this operation.
    ./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

    A similar output is displayed, which indicates 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

If you use ossutil to switch to a bucket that is located in a different region, you can use the -e option to specify the endpoint of the region in which the specified bucket resides. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, you can use the -i option to specify the AccessKey ID of the specified account, and use the -k option to specify 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 belongs to another Alibaba Cloud account:

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