The rm command is used to delete a bucket, an object, or a part.

Note The commands described in this topic apply to Linux. To use the commands in other systems, replace ./ossutil in the command with the actual executable program name. For example, you can use the help command in 32-bit Windows systems by running ossutil32.exe help.

Command syntax

./ossutil rm oss://bucket[/prefix] [-r] [-b] [-f][-c file] [--include include-pattern] [--payer requester] [--exclude exclude-pattern]

Examples

  • Delete an empty bucket
    ./ossutil rm oss://bucket1 -b
    Notice
    • To delete a bucket, you must configure the -b option.
    • Deleted buckets can be re-created by other users, at which point you will no longer be able to use the buckets.
  • Clear bucket data and delete the bucket
    If the bucket contains data such as objects or parts, you must delete all data stored in the bucket before the bucket can be deleted. The command is as follows:
    ./ossutil rm oss://bucket1 -bar
    Warning This command will clear all data in the bucket. Exercise caution when using this command.
  • Delete a single object
    ./ossutil rm oss://bucket1/path/object
  • Delete all objects that have a specified prefix
    You can add the -r option to the rm command to recursively delete all objects that have a specified prefix.
    ./ossutil rm oss://bucket1/path/ -r
  • Delete multiple objects that meet specified conditions
    You can configure --include and --exclude options to delete objects that meet specified conditions. For more information about --include and --exclude, see cp.
    • Delete all objects except .jpg objects.
      ./ossutil rm oss://my-bucket/path  --exclude "*.jpg" -r
    • Delete all objects that contain abc in their names and are not in JPG or TXT format.
      ./ossutil rm oss://my-bucket1/path  --include "*abc*" --exclude "*.jpg" --exclude "*.txt" -r
  • Delete the upload IDs of incomplete multipart upload tasks initiated to a specified object
    You can add the -m option to the rm command to delete the upload IDs of incomplete multipart upload tasks initiated to a specified object.
    ./ossutil rm -m oss://bucket1/obj1/test.txt
    Succeed: Total 1 uploadIds. Removed 1 uploadIds. 
    0.900715(s) elapsed
  • Delete the upload IDs of all incomplete multipart upload tasks initiated to objects that have a specified prefix
    You can add the -m and -r options to the rm command to delete the upload IDs of all incomplete multipart upload tasks initiated to objects that have a specified prefix.
    ./ossutil rm -m oss://bucket1/ob -r 
    Do you really mean to remove recursively multipart uploadIds of oss:bucket1/ob(y or N)? y 
    Succeed: Total 4 uploadIds. Removed 4 uploadIds. 
    1.922915(s) elapsed
  • Delete the upload IDs of all incomplete multipart upload tasks initiated to objects with a specified prefix and the uploaded objects with the prefix
    You can add the -a and -r options to the rm command to delete the upload IDs of all incomplete multipart upload tasks initiated to objects with a specified prefix and the uploaded objects with the prefix.
    ./ossutil rm  oss://hello-hangzws-1/obj -a -r
    Do you really mean to remove recursively objects and multipart uploadIds of oss://obj(y or N)? y
    Succeed: Total 1 objects, 3 uploadIds. Removed 1 objects, 3 uploadIds.
  • Delete a specified version of an object in a versioning-enabled bucket
    ./ossutil.exe rm oss://bucket1/test.jpg --version-id  CAEQARiBgID8rumR2hYiIGUyOTAyZGY2MzU5MjQ5ZjlhYzQzZjNlYTAyZDE3MDRk
    To use the --version-id option, you must run the ls --all-versions command to obtain version IDs of the object.
    Note The --version-id option can only be used for objects in versioning-enabled buckets. For more information about the command used to enable versioning on a bucket, see bucket-versioning.
  • Delete all versions of a specified object in a versioning-enabled bucket
    ./ossutil.exe rm oss://bucket1/test.jpg --all-versions
    Succeed: Total 2 objects. Removed 2 objects.
  • Delete all versions of all objects in a versioning-enabled bucket
    ./ossutil.exe rm oss://bucket1/ --all-versions -r

Common options

The following table describes the options you can add to the rm command to delete different content.
Option Description
-r, --recursive Recursively performs operations on objects in a bucket. If this option is specified, the command that support this option will perform operations on all objects in a bucket that meet the specified conditions. If this option is not specified, the command will only perform operations on a single specified object.
-b, --bucket Specifies the bucket on which to perform an operation.
-m, --multipart Specifies that operations are only to be performed on uncompleted multipart upload tasks in a bucket instead of objects.
-a, --all-type Specifies that operations are to be performed on both the objects and uncompleted multipart upload tasks in a bucket.
-f, --force Specifies whether to force an operation without prompting the user for confirmation.
--encoding-type Specifies the method used to encode the object name. If this option is specified, this value must be url. If this option is not specified, the object name is not encoded. Bucket names cannot be URL-encoded.
--retry-times= Specifies the number of times an operation is retried if the operation fails. Valid values: 1 to 500. Default value: 10.
--loglevel Specifies the log level. The default value is null, indicating that no log files are generated. Valid values:
  • info: generates prompt logs.
  • debug: generates detailed logs that contain corresponding HTTP request and response information.
--include Includes objects that match a specified string, such as *.jpg.
--exclude Excludes objects that match a specified string, such as *.txt.
--version-id Deletes a specified version of an object. This option can only be used for objects in a versioning-enabled bucket.
--all-versions Deletes all versions of a specified object. This option can only be used for objects in a versioning-enabled bucket.
--payer Specifies the payer of the request. To enable pay-by-requester, set this option to requester.
--proxy-host Specifies the URL of the proxy server. HTTP, HTTPS, and SOCKS5 proxies are supported. An example of the URL is http://120.79. **.**:3128 or socks5://120.79. **. **:1080.
--proxy-user Specifies the username for the proxy server. The default value is null.
--proxy-pwd Specifies the password for the proxy server. The default value is null.
Note For more information about common options, see View all supported options.