tencent cloud

Deleting Objects - rm
Last updated: 2025-05-09 18:27:39
Deleting Objects - rm
Last updated: 2025-05-09 18:27:39
The rm command is used to delete an object.
Note:
To use the rm command, please download COSCLI V1.0.1 or above. For details, see Download and Installation Configuration.
If your current version of COSCLI is V1.0.0, please upgrade to V1.0.1 before executing the rm command. In V1.0.0, the --include and --exclude parameters do not work when executing the rm command, which may lead to unexpected deletion situations.
If you need to use this command to delete an object, when you perform authorization policy, set action to cos:HeadBucket, cos:HeadObject, cos:GetBucket, cos:DeleteObject, cos:DeleteMultipleObjects.
If you need to use this command to delete a historical version (such as importing --all-versions or --version-id), when you perform authorization policy, set action to cos:HeadBucket, cos:HeadObject, cos:GetBucket, cos:DeleteObject, cos:DeleteMultipleObjects, cos:GetBucketVersioning, cos:GetBucketObjectVersions.
For more authorizations, please refer to CAM-Enabled API.If you have any questions or need further assistance, please contact us.

Command Syntax

./coscli rm cos://<bucket-name>[/prefix/] [flag]
rm includes the following parameters:
Parameter Format
Description
Example
cos://<bucket-name>
Specifies the target bucket, which is accessible by using the bucket alias or bucket name configured in the configuration file as detailed in Download and Installation Configuration. If you use the bucket name for access, you also need to include the endpoint flag.
Access with the bucket alias: cos://example-alias
Access with the bucket name: cos://examplebucket-1250000000
/prefix/
Specifies a directory (optional).
/picture/
rm includes the following optional flags:
Flag Abbreviation
Flag Name
Description
-h
--help
Views the usage of this command.
None
--include
Includes specific objects.
None
--exclude
Excludes specific objects.
-r
--recursive
Specifies whether to traverse all objects in the directory recursively.
-f
--force
Forces deletion (no prompt before the deletion).
None
--fail-output
This option determines whether to enable the error output of files when upload or download fails (The default value is true, enabled). If enabled, failed file transfers will be recorded in the specified directory (If no directory is specified, the default directory ./coscli_output is used). If disabled, only the number of failed files will be output to the console.
None
--fail-output-path
This option is used to specify the error output folder for recording failed file uploads or downloads. By providing a custom folder path, you can control the location and name of the error output folder. If this option is not set, the default error log folder ./coscli_output is used.
None
--all-versions
Available only in buckets with versioning enabled and when importing the --recursive (-r) parameter, traverse and delete all versions under the specified path.
None
--version-id
Available only in a Bucket with versioning enabled and when --recursive (-r) parameter is not passed in, to delete the specified version of a specified object.
Note:
--include and --exclude support standard regular expression syntax, so you can use them to filter out objects that meet specific criteria.
When using zsh, you may need to add double quotes at both ends of the pattern string.
./coscli rm cos://bucket1/example/ -r --include ".*\\.mp4$"
For more general options for this command (such as switching buckets or user accounts), see Common Options.

Example

Deleting the fig1.png object

./coscli rm cos://bucket1/fig1.png

Deleting all objects in the picture directory

./coscli rm cos://bucket1/pictrue/ -r

Deleting the Specified Version of the fig1.png File

./coscli rm cos://bucket1/fig1.png --version-id xxx

Deleting All Versions with the test Prefix

./coscli rm cos://bucket1/test -r --all-versions
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback