Scenarios
You can use OBS Console, APIs, SDKs, OBS Browser+, or obsutil to delete unneeded files or folders, helping save space and reduce costs.
This section describes how to delete files or folders. For details, see Table 1.
Table 1 Object deletion methods | Scenario | Method | Description |
| In a bucket with versioning disabled | Individual deletion | To delete a small number of objects or objects without a clear pattern, select a specific object and delete it. |
| Batch deletion | To delete a large number of objects or periodically generated objects, select multiple objects and delete them in a batch. You can also use lifecycle rules to periodically delete objects for higher efficiency. For details, see Lifecycle Rules. |
| In a bucket with versioning enabled or suspended | Individual deletion | To delete a small number of objects or objects without a clear pattern, select a specific object and delete it. |
| Batch deletion | To delete a large number of objects or periodically generated objects, select multiple objects and delete them in a batch. You can also use lifecycle rules to periodically delete objects for higher efficiency. For details, see Lifecycle Rules. |
In big data scenarios, parallel file systems often have deep directory hierarchies, and each directory contains a large number of files. As a result, directory deletion may time out. To address this issue, you can delete directories in either of the following ways:
- On a Hadoop client with OBSA embedded, run hadoop fs - rmr obs://{parallel-file-system-name}/{directory-name}.
- Configure a lifecycle rule for directories so that they can be deleted automatically in the background.
Important Notes
You can back up important objects to prevent accidental deletion. For details, see Copying Objects.
Access Control
Only the object owner and users granted the obs:object:DeleteObject (versioning disabled) or obs:object:DeleteObjectVersion (versioning enabled or suspended) permission can delete an object. The permissions can be granted through IAM or bucket policies. For details, see Creating a Custom Policy or Creating a Custom Bucket Policy.
If you have the required deletion permission in an IAM policy but still cannot delete an object, a Deny statement for obs:object:DeleteObject (versioning disabled) or obs:object:DeleteObjectVersion (versioning enabled or suspended) may be present in an SCP policy or bucket policy. Allow the permission and then delete the object.
How Object Deletion Works with Other Features
OBS versioning keeps multiple versions of an object in the same bucket. You can quickly search for and restore any version and recover data in the event of unintended actions or application failures. Deleting objects may cause data loss. Versioning reduces this risk by allowing you to restore objects that are accidentally deleted or overwritten. For more information, see Versioning.
| Scenario | Deleting the Current Object Version | Deleting a Historical Object Version |
| In a bucket with versioning disabled | OBS permanently deletes objects. Deleted objects cannot be recovered. | N/A |
| In a bucket with versioning suspended | - If an object's current version does not have a delete marker and its version ID is not null, the object deletion operation turns the current version into a historical version and inserts a delete marker with an ID of null. The delete marker then becomes the current version.
- If an object's current version does not have a delete marker and its version ID is null, the object deletion operation inserts a delete marker with a null version ID that overwrites the current version. The delete marker then becomes the current version, and the overwritten version cannot be recovered.
- If the current version has a delete marker, no action is taken.
NOTE: - After versioning is suspended, a newly uploaded object will have a null version ID. If the new object has the same name as an existing object with a null version ID, it overwrites the existing object.
- By enabling Historical Versions above the object list, you can view the version ID of an object.
| Deleted historical versions cannot be recovered. |
| In a bucket with versioning enabled | - If an object's current version does not have a delete marker, the object deletion operation inserts a delete marker. Then, the current version becomes a historical version and the delete marker becomes the current version.
- If an object's current version has a delete marker, permanently deleting the current version recovers the object.
| Deleted historical versions cannot be recovered. |
OBS automatically enables versioning when you enable WORM for a bucket. If you delete an object without specifying a version ID, OBS does not actually delete the object because of versioning. Instead, it inserts a delete marker with a unique version ID, which turns into the current version. If you specify a version ID when deleting an object protected by WORM, OBS blocks the deletion. Delete markers are not protected by WORM.
You can configure lifecycle rules to periodically delete unneeded objects to free up storage and reduce costs. When a lifecycle rule is executed, OBS performs different deletion operations on objects depending on the bucket's versioning status. For more information, see Using Lifecycle Rules to Delete or Transition Objects.
Ways to Delete Objects
You can use OBS Console, APIs, SDKs, OBS Browser+, or obsutil to delete files or folders. Up to 1,000 objects can be deleted at a time.
Deleting objects individually
- In the navigation pane of OBS Console, choose Buckets.
- In the bucket list, click the desired bucket. The Objects page is displayed.
- Select the file or folder you want to delete and choose More > Delete on the right.
Figure 1 Deleting a file or folder
- Click OK to confirm the deletion.
Figure 2 Deleting an object
If you delete an object from a bucket with versioning enabled, the object is not permanently deleted but retained in the Deleted Objects list. All versions of the object are still kept in the bucket and are billed for storage. If you need to permanently delete the object, complete the following steps:
Batch deleting objects
To delete a large number of objects or periodically generated objects, select multiple objects and delete them in a batch.
- In the navigation pane of OBS Console, choose Buckets.
- In the bucket list, click the desired bucket. The Objects page is displayed.
- Select all files or folders or only the ones you want to delete and click Delete above the object list.
- Click OK to confirm the deletion.
You can also use lifecycle rules to periodically delete objects for higher efficiency. For details, see Lifecycle Rules.
Deleting objects individually
- In the navigation pane of OBS Console, choose Buckets.
- In the bucket list, click the desired bucket. The Objects page is displayed.
- Enable Historical Versions.
- Select the file or folder to delete and click Permanently Delete above the search box.
Figure 3 Permanently deleting an object
- In the dialog box, click OK.
Batch deleting objects
- In the navigation pane of OBS Console, choose Buckets.
- In the bucket list, click the desired bucket. The Objects page is displayed.
- Enable Historical Versions.
- Select all files or folders or only the ones you want to delete and click Permanently Delete above the search box.
- In the dialog box, click OK.
Using SDKs
Using the SDK for BrowserJS to interact with OBS exposes the AK and SK on the frontend, which introduces security risks. To avoid this, the frontend can use a temporarily signed URL generated by the backend to access OBS. For details, see How Do I Interact with OBS Without Exposing My AK and SK?
Using the GUI Tool - OBS Browser+
- Log in to OBS Browser+.
- Go to the bucket from which you want to delete a file or folder.
- Right-click the file or folder to be deleted and click Delete.
You can select multiple files or folders and choose More > Delete above the list to batch delete them.
- After selecting the files or folders to be deleted, click Yes in the confirmation dialog box.
Using the CLI Tool - obsutil
Command Line Structure
- Windows
- Deleting a single object
obsutil rm obs://bucket/key [-f] [-versionId=xxx] [-fr] [-o=xxx] [-config=xxx] [-e=xxx] [-i=xxx] [-k=xxx] [-t=xxx]
- Deleting objects in batches
obsutil rm obs://bucket/[key] -r [-j=1] [-f] [-v] [-o=xxx] [-config=xxx] [-e=xxx] [-i=xxx] [-k=xxx] [-t=xxx]
- macOS or Linux
- Deleting a single object
./obsutil rm obs://bucket/key [-f] [-versionId=xxx] [-fr] [-o=xxx] [-config=xxx] [-e=xxx] [-i=xxx] [-k=xxx] [-t=xxx]
- Deleting objects in batches
./obsutil rm obs://bucket/[key] -r [-j=1] [-f] [-v] [-o=xxx] [-config=xxx] [-e=xxx] [-i=xxx] [-k=xxx] [-t=xxx]
Examples
- In Windows, run obsutil rm obs://bucket-test/key -f to delete the key object in bucket bucket-test.
obsutil rm obs://bucket-test/key -f
Start at 2024-09-25 04:48:10.1147483 +0000 UTC
Delete object [key] in the bucket [bucket-test] successfully, cost [152], request id [0000016979E1D2B2860BB5181229C72C]
Parameter Description
| Parameter | Optional or Mandatory | Description |
| bucket | Mandatory | The bucket name |
| key | Mandatory for deleting a single object. Optional for deleting objects in batches. | The name of the object to be deleted, or the name prefix of the objects to be deleted in batches NOTE: If this parameter is left blank when deleting objects in batches, all objects in the bucket are deleted. Use this parameter with caution. |
| fr | Optional for deleting a single object (additional parameter) | Generates an operation result file when deleting an object. |
| f | Optional (additional parameter) | Performs operations without asking for confirmation. Use this parameter with caution. |
| versionId | Optional for deleting a single object (additional parameter) Mandatory for deleting object versions | The version ID of the object to be deleted. |
| r | Mandatory for deleting objects in batches (additional parameter) | Deletes objects in batches based on a specified object name prefix. CAUTION: When you batch delete objects, all objects with the specified prefix will be deleted. |
| j | Optional for deleting objects in batches (additional parameter) | The maximum number of concurrent tasks for deleting objects in batches. The default value is the value of defaultJobs in the configuration file. NOTE: The tool ensures that this value is at least 1. |
| v | Optional for deleting objects in batches (additional parameter) | Deletes versions of an object and the delete markers in batches based on a specified object name prefix. |
| o | Optional (additional parameter) | The folder that stores the result files. After the command is executed, result files (possibly success and failure files) will be created in the specified folder. The default value is .obsutil_output, a subfolder in the user's home directory where obsutil commands are executed. NOTE: - A result file should be named as follows: rm_{succeed | failed}_report_Time_TaskId.txt.
- By default, the maximum size of a single result file is 30 MB and up to 1,024 result files can be retained. You can modify these limits by configuring recordMaxLogSize and recordBackups in the configuration file.
- If there are multiple folders and files and you need to confirm the details of a failed task, refer to the failure result file cp_failed_report_Time_TaskId.txt in the result folder and the log files in the log path.
|
| bucket-cname | Optional (additional parameter) | The user-defined domain name bound to the bucket NOTE: This parameter is only supported by obsutil 5.7.9 and later. |
| config | Optional (additional parameter) | The user-defined configuration file for executing the current command. For details about parameters that can be configured, see Configuration Parameters. |
| e | Optional (additional parameter) | The endpoint |
| i | Optional (additional parameter) | The user's AK |
| k | Optional (additional parameter) | The user's SK |
| t | Optional (additional parameter) | The user's security token |
Response
| Field | Description |
| Parallel | The parameter -p in the request |
| Jobs | The parameter -j in the request |
| Threshold | The parameter -threshold in the request |
| PartSize | The parameter -ps in the request |
| Exclude | The parameter -exclude in the request |
| Include | The parameter -include in the request |
| TimeRange | The parameter -timeRange in the request |
| VerifyLength | The parameter -vlength in the request |
| VerifyMd5 | The parameter -vmd5 in the request |
| CheckpointDir | The parameter -cpd in the request |
| OutputDir | The parameter -o in the request |
| ArcDir | The parameter -arcDir in the request |
| Succeed count | The number of successful tasks |
| Failed count | The number of failed tasks |
| Skip count | The number of tasks that are skipped during incremental upload, download, or copy, and synchronous upload, download, or copy. NOTE: Skipped tasks are recorded into successful tasks. |
| Warning count | The number of tasks that are executed successfully but contain warnings. NOTE: - The task for which a warning is generated may be a failure or a success, which needs to be further determined according to the corresponding result list.
- The number of tasks that generate warnings is independent of the number of successful or failed tasks. The total number of tasks is the number of successful tasks plus the number of failed tasks.
|
| Succeed bytes | The number of bytes that are successfully uploaded or downloaded. |
| max cost | The maximum duration of all tasks, in ms |
| min cost | The minimum duration of all tasks, in ms |
| average cost | The average duration of all tasks, in ms |
| average tps | The average number of tasks completed per second |
| Task id | The unique ID of an operation, which is used to search for the result file generated for a batch task |
Logging and Monitoring
OBS provides logging and monitoring features that help you detect and handle deletion operations promptly. You can configure REST.PUT.NOTIFICATION to monitor object deletion. The system will record detailed logs for all object deletion operations for auditing or further analysis. For details, see Using Logging to Record OBS Logs.