Delete multiple objects from the same bucket in a single request. You can delete up to 1,000 objects per request.
Deleted objects cannot be recovered. Proceed with caution.
Prerequisites
Before you begin, ensure that you have:
The
oss:DeleteObjectpermission. By default, an Alibaba Cloud account has this permission. RAM users and Security Token Service (STS) users must be granted this permission explicitly. See Attach a custom policy to a RAM user.
Command syntax
ossutil api delete-multiple-objects --bucket <bucket-name> --delete <delete-config> [flags]Required parameters
| Parameter | Type | Description |
|---|---|---|
--bucket | string | Name of the bucket. |
--delete | string | Deletion configuration in XML or JSON format. See the --delete format section below. |
Optional parameters
| Parameter | Type | Description |
|---|---|---|
--encoding-type | string | Encoding type for object names in the response. |
For all supported flags, see Command-line options.
This command maps to the DeleteMultipleObjects API operation. For a full parameter reference, see the API documentation.
--delete format
The --delete parameter accepts XML or JSON. Use the file:// prefix to load the configuration from a file.
Key fields:
| Field | Type | Required | Description |
|---|---|---|---|
Quiet | string | No | Controls the response content. When true, the response lists only objects that failed to delete. When false (default), the response lists all deleted objects. |
Key | string | Yes | The object key (name or path) of the object to delete. |
VersionId | string | No | The version ID of the specific object version to delete. Omit this field to delete the current version. |
XML format:
<Delete>
<Quiet>false</Quiet>
<Object>
<Key>string</Key>
<VersionId>string</VersionId>
</Object>
<Object>
<Key>string</Key>
<VersionId>string</VersionId>
</Object>
</Delete>JSON format:
{
"Quiet": "false",
"Object": [
{
"Key": "string",
"VersionId": "string"
},
{
"Key": "string",
"VersionId": "string"
}
]
}Examples
Delete multiple objects using an XML file
Create a file named delete.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Delete>
<Quiet>false</Quiet>
<Object>
<Key>multipart.data</Key>
</Object>
<Object>
<Key>test.jpg</Key>
</Object>
</Delete>Run the command:
ossutil api delete-multiple-objects --bucket examplebucket --delete file://delete.xmlDelete multiple objects using a JSON file
Create a file named delete.json:
{
"Quiet": "false",
"Object": [
{
"Key": "multipart.data"
},
{
"Key": "test.jpg"
}
]
}Run the command:
ossutil api delete-multiple-objects --bucket examplebucket --delete file://delete.jsonDelete multiple objects with inline JSON
Pass the deletion configuration directly in the command:
ossutil api delete-multiple-objects --bucket examplebucket --delete "{\"Quiet\":\"false\",\"Object\":[{\"Key\":\"multipart.data\"},{\"Key\":\"test.jpg\"}]}"Delete specific versions of multiple objects
To delete specific versions of objects in a versioning-enabled bucket, include the VersionId field for each object.
Create a file named delete.json:
{
"Quiet": "false",
"Object": [
{
"Key": "multipart.data",
"VersionId": "CAEQNRiBgIDyz.6C0BYiIGQ2NWEwNmVhNTA3ZTQ3MzM5ODliYjM1ZTdjYjA4****"
},
{
"Key": "test.jpg",
"VersionId": "CAEQMhiBgIDB3aWB0BYiIGUzYTA3YzliMzVmNzRkZGM5NjllYTVlMjYyYWEy****"
}
]
}Run the command:
ossutil api delete-multiple-objects --bucket examplebucket --delete file://delete.jsonTo pass version IDs inline:
ossutil api delete-multiple-objects --bucket examplebucket --delete "{\"Quiet\":\"false\",\"Object\":[{\"Key\":\"multipart.data\",\"VersionId\":\"CAEQNRiBgIDyz.6C0BYiIGQ2NWEwNmVhNTA3ZTQ3MzM5ODliYjM1ZTdjYjA4****\"},{\"Key\":\"test.jpg\",\"VersionId\":\"CAEQMhiBgIDB3aWB0BYiIGUzYTA3YzliMzVmNzRkZGM5NjllYTVlMjYyYWEy****\"}]}"