Deleting objects that you no longer need helps you reduce storage costs, comply with data retention requirements, and keep your buckets organized. Depending on your scale and automation needs, you can choose from several methods to delete objects manually, programmatically, or through automated policies.
This page describes the methods available for deleting objects from your buckets and helps you choose a suitable method for your task.
For information about how to delete objects, see Delete objects.
Single-object deletion
Single-object deletion provides precise control over specific data. You typically delete single objects when you need to perform immediate, targeted updates to your bucket's data. The following are some of the common reasons for deleting single objects:
Correcting errors: Removing a file that was uploaded accidentally or a file that contains incorrect data.
Cleanup: Manually removing temporary files or logs after completing a task.
Application logic: Automatically removing a file when you perform an action in an application, such as deleting a profile photo.
Security and compliance: Deleting objects as part of removing sensitive information.
Tools to delete a single object
To delete a single object from your bucket, use any of the following tools. Each tool sends an individual DELETE request per object.
| Tool | Description |
|---|---|
| Cloud de Confiance console | Deletes an object through the Cloud de Confiance console. |
| Google Cloud CLI | Deletes an object using the gcloud storage rm command. |
| Client libraries | Deletes an object programmatically using a supported language like C++, C#, Go, Java, Node.js, PHP, Python, or Ruby. |
| REST APIs | Deletes an object using JSON and XML REST APIs. |
Bulk object deletion
Bulk deletion methods are designed for high-efficiency operations on large datasets. Use bulk deletion to manage storage costs and automate data hygiene across buckets. The following are some of the common reasons for deleting multiple objects:
Cost optimization: Removing large datasets, such as old logs or temporary build artifacts, that are no longer needed for operations.
Compliance automation: Automatically enforcing data retention policies by deleting objects after a specific period, for example, 30 days.
Bucket migration or decommissioning: Clearing out millions or billions of objects when migrating data or closing a project.
Data pipeline cleanup: Removing intermediate processing files after a final report or dataset has been generated.
Tools to delete objects in bulk
To delete objects in bulk, use one of the following tools. These methods are optimized for higher throughput and reduced overhead compared to individual requests.
| Tool | Description |
|---|---|
| Delete multiple objects using the XML API | A programmatic method to delete up to 1,000 objects in a single When using the XML API to delete multiple objects, Cloud Storage generates data access audit logs. These logs include details on the overall request and individual object deletions, provided that you enable the data access audit logs. For details, see Audit logs for multi-object delete XML API. The multi-object delete XML API has the following limitations:
|
| Cloud de Confiance console | The Cloud de Confiance console is a recommended option when deleting up to one million objects. After you initiate a deletion request, the process occurs in the background. You can check the status of your bulk deletion by clicking the Notifications button ( notifications) in the Cloud de Confiance console header. |
| Storage batch operations | A fully managed service that performs deletions based on a manifest file. Suitable for deleting up to billions of objects with built-in tracking and retries. We recommend using storage batch operations if you want to do the following:
|
gcloud storage rm --recursive |
A Google Cloud CLI command to delete all objects sharing a common prefix. Suitable for small-to-medium scale bulk tasks using the CLI. |
| Object Lifecycle Management | A server-side feature that deletes objects automatically based on rules you define, such as object age or storage class. To bulk delete objects in your bucket, set a lifecycle
configuration rule on your bucket where the condition has Age
set to 0 days and the action is set to delete. After you set the
rule, Cloud Storage performs
the bulk delete asynchronously.
|
| Batch requests | When using certain client libraries or when using the JSON API directly, you can batch your deletion requests to reduce the number of HTTP connections that you need. |
Choose a deletion method
The tool for deleting objects depends on how many objects you need to delete and why. Use the following guidance to choose a method for your use case:
- If you need to delete one or only a few specific objects, use the
Cloud de Confiance console,
gcloud storage rm, or single API calls using client libraries or REST APIs. For details, see Delete a single object. - If you need to delete up to 1,000 objects in a single API request, use the multi-object delete XML API, the Amazon S3 CLI, or an S3-compatible client library like Boto3. For details, see Delete objects in bulk.
- If you are deleting many objects that share a common name prefix,
use the
gcloud storage rm --recursivecommand. For details, see Delete objects in bulk using Google Cloud CLI. - If you need to delete millions or billions of objects, use Storage batch operations for reliable large-scale deletions.
- If you need to automatically delete objects when they meet certain criteria, use Object Lifecycle Management.
What's next
- Delete a bucket when it's no longer needed.
- Learn about Object Versioning, which lets you keep multiple versions of an object in the same bucket.
- Configure Object Lifecycle Management to automate object deletions and other actions based on conditions.
- Perform large-scale object deletions efficiently with storage batch operations.
- Help protect objects from accidental deletion by using soft delete.
- Understand how Object Retention Lock and Bucket Lock can help enforce data retention policies.