All Products
Search
Document Center

Object Storage Service:rm (delete)

Last Updated:Jul 04, 2025

You can use the rm command to delete files that you no longer need.

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 you want to delete.

--all-versions

/

Specifies all versions of an object.

-d, --dirs

/

Returns objects and subdirectories in the current directory, instead of recursively displaying all objects in all subdirectories.

--encoding-type

string

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

--end-with

string

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

--exclude

stringArray

The exclusion rule for paths or object names.

--exclude-from

stringArray

Reads exclusion rules from a file.

--files-from

stringArray

Reads a list of source object names from a file, with empty lines or comment lines ignored.

--files-from-raw

stringArray

Reads a list of source objects from a file.

--filter

stringArray

The filter rule for paths or object names.

--filter-from

stringArray

Reads filter rules from a file.

-f, --force

/

Specifies that the operation is forcibly performed without a prompt for confirmation.

--include

stringArray

The inclusion rule for paths or object names.

--include-from

stringArray

Reads inclusion rules from a file.

--limited-num

int

The maximum number of returned results.

--list-objects

/

Lists objects by calling the ListObjects operation.

--max-size

SizeSuffix

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

--metadata-exclude

stringArray

The exclusion rules for object metadata.

--metadata-filter

stringArray

The filter rules for object metadata.

--metadata-filter-from

stringArray

Reads metadata filter rules from a file.

--metadata-include

stringArray

The inclusion rules for object metadata.

--min-age

Duration

Deletes only files that were modified before the specified time interval. The default unit is seconds. You can use the unit suffix format. For example, 1h indicates one hour.

Note

--min-age 1h indicates that only files that were modified 1 hour ago or earlier are deleted.

--max-age

Duration

Deletes only files that were modified within the specified time interval. The default unit is seconds. You can use the unit suffix format. For example, 1h indicates one hour.

Note

--max-age 1h indicates that only files that were modified within the last hour are deleted.

--min-mtime

Time

Deletes only files that were modified after the specified time. Time format: UTC. Example: 2006-01-02T15:04:05.

Note

--min-mtime "2006-01-02T15:04:05" indicates that only files that were modified after January 2, 2006, 15:04:05 are deleted.

--max-mtime

Time

Deletes only files that were modified before the specified time. Time format: UTC. Example: 2006-01-02T15:04:05.

--min-size

SizeSuffix

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

-m, --multipart

/

Deletes all incomplete or uncanceled upload parts.

--page-size

int

The maximum number of objects to list per page during batch processing (default value: 1000). Valid values: 1 to 1000.

-r, --recursive

/

Specifies recursion. If this parameter is specified, the command performs the operation on all matching objects in the bucket. If this parameter is not specified, the command performs the operation only on the specified 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 with names containing the test prefix from a bucket named examplebucket:

    ossutil rm oss://examplebucket/test -r
  • Delete all objects with names ending in .png from a bucket named examplebucket:

    ossutil rm oss://examplebucket  --include "*.png" -r
  • Delete files from examplebucket that meet any of the following conditions:

    • The file name contains the "abc" string

    • The file name extension is not .jpg

    • The file name extension is not .txt

    ossutil rm oss://examplebucket  --include "*abc*" --exclude "*.jpg" --exclude "*.txt" -r
  • Delete a specific version of an object named exampleobject.txt from a versioned 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
  • Delete all incomplete or uncanceled upload parts:

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