All Products
Search
Document Center

Object Storage Service:rm

Last Updated:Jul 31, 2024

You can run the rm command to delete objects that you no longer need.

Command syntax

ossutil rm oss://bucket[/prefix] [flags]

Parameter

Type

Description

prefix

string

The directory in which the objects you want to delete are stored, or the prefix that is contained in the names of the objects that you want to delete.

--all-versions

/

All versions of an object.

-d, --dirs

/

Specifies that the objects and subdirectories in the current directory are returned.

--encoding-type

string

The encoding method used to encode the object name. Valid value: url.

--end-with

string

Specifies that objects whose names are alphabetically before or the same as the value of the --end-with parameter are returned.

--exclude

stringArray

The exclusion rule for the path or object name.

--exclude-from

stringArray

Specifies that the exclusion rule is read from the rules file.

--files-from

stringArray

Specifies that the source object names are read from the rules file, and empty lines or comment lines are ignored.

--files-from-raw

stringArray

Specifies that the source object names are read from the rules file.

--filter

stringArray

The filter rule for the path or object name.

--filter-from

stringArray

Specifies that the filter rule for the path or object name is read from the rules file.

-f, --force

/

Specifies that the command is forcibly run without a prompt for confirmation.

--include

stringArray

The inclusion rule for the path or object name.

--include-from

stringArray

Specifies that the inclusion rule is read from the rules file.

--limited-num

int

The maximum number of results to return.

--list-objects

/

Specifies that the ListObjects operation is called to list objects.

--max-age

Duration

Specifies that the objects whose last modified time is earlier than the value of the --max-age parameter are not deleted. The default unit is seconds. The unit can be milliseconds, seconds, minutes, hours, days, weeks, months, or years. By default, this parameter is left empty.

--max-mtime

Time

Specifies that the objects whose last modified time is later than the value of the --max-mtime parameter are not deleted. The value is in UTC. By default, this parameter is left empty.

--max-size

SizeSuffix

Specifies the maximum size of the object that can be deleted. The default unit is bytes. The unit of object size can be bytes, KiB, MiB, GiB, TiB, or PiB. Note: 1 KiB = 1,024 bytes.

--metadata-exclude

stringArray

The exclusion rule for object metadata.

--metadata-filter

stringArray

The filter rule for object metadata.

--metadata-filter-from

stringArray

Specifies that the filter rule for object metadata is read from the rules file.

--metadata-include

stringArray

The inclusion rule for object metadata.

--min-age

Duration

Specifies that the objects whose last modified time is later than the value of the --min-age parameter are not deleted. The default unit is seconds. The unit can be milliseconds, seconds, minutes, hours, days, weeks, months, or years. By default, this parameter is left empty.

--min-mtime

Time

Specifies that the objects whose last modified time is earlier than the value of the --min-mtime parameter are not deleted. The value is in UTC. By default, this parameter is left empty.

--min-size

SizeSuffix

Specifies the minimum size of the object that can be deleted. The default unit is bytes. The unit of object size can be bytes, KiB, MiB, GiB, TiB, or PiB. Note: 1 KiB = 1,024 bytes.

--page-size

int

The maximum number of objects that can be returned. Default value: 1000. Valid values: 1 to 1000.

-r, --recursive

/

Specifies that the command is recursively run on objects. If this parameter is specified, the rm command takes effect on all objects that meet the conditions in the bucket. Otherwise, the rm command takes effect only on the objects in the specified path.

--request-payer

string

The payer of the request. If pay-by-requester is enabled for the bucket, set this parameter to requester.

--start-after

string

Specifies that objects whose names are alphabetically after the value of the --start-after parameter are returned.

--version-id

string

The version ID of the object.

Note

For more information, see Command-line options.

Examples

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

    ossutil rm oss://examplebucket/exampleobject.txt
  • Delete all objects whose names contain the test prefix from a bucket named examplebucket:

    ossutil rm oss://examplebucket/test -r
  • Delete all objects whose names contain the .png suffix from a bucket named examplebucket:

    ossutil rm oss://examplebucket  --include "*.png" -r
  • Delete objects whose names contain the abc string and do not contain the .jpg or .txt suffix from a bucket named examplebucket:

    ossutil rm oss://examplebucket  --include "*abc*" --exclude "*.jpg" --exclude "*.txt" -r
  • Delete a specific version of an object named exampleobject.txt from a versioning-enabled bucket named examplebucket:

    ossutil rm oss://examplebucket/exampleobject.txt --version-id  CAEQARiBgID8rumR2hYiIGUyOTAyZGY2MzU5MjQ5ZjlhYzQzZjNlYTAyZDE3****
  • Delete all versions of an object named exampleobject.txt from a versioning-enabled bucket named examplebucket:

    ossutil rm oss://examplebucket/exampleobject.txt --all-versions
  • Delete all versions of all objects from a versioning-enabled bucket named examplebucket:

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