This page shows you how to delete objects from your buckets in Cloud Storage. For an overview of object deletion methods, see About object deletion.
Required roles
To get the permissions that you need to delete objects, ask your administrator to grant you the following IAM roles on the bucket that contains the objects you want to delete:
-
Delete objects using Google Cloud CLI or REST APIs:
Storage Object User (
roles/storage.objectUser) -
Delete objects using the Google Cloud console:
Storage Admin (
roles/storage.admin) -
Alternatively, to delete objects using the Google Cloud console:
Viewer (
roles/viewer) and Storage Object User (roles/storage.objectUser)
For more information about granting roles, see Manage access to projects, folders, and organizations.
These predefined roles contain the permissions required to delete objects. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to delete objects:
-
Delete objects:
storage.objects.delete -
List objects using the Google Cloud console, or using the
--recursiveflag or wildcards in Google Cloud CLI:storage.objects.list -
List buckets using the Google Cloud console:
storage.buckets.list
You might also be able to get these permissions with custom roles or other predefined roles.
Delete a single object
This section shows how to delete one object at a time.
Complete the following steps to delete a single object:
Console
- In the Google Cloud console, go to the Cloud Storage Buckets page.
In the list of buckets, click the name of the bucket that contains the objects you want to delete.
The Bucket details page opens, with the Objects tab selected.
Navigate to the object, which may be located in a folder.
Select the checkbox for the object you want to delete.
Click Delete, and then click Delete in the dialog that appears.
Command line
Use the Google Cloud CLI command gcloud storage rm:
gcloud storage rm gs://BUCKET_NAME/OBJECT_NAME
Where:
BUCKET_NAMEis the name of the bucket containing the object you want to delete. For example,my-bucket.OBJECT_NAMEis the name of the object you want to delete. For example,pets/dog.png.
If successful, the response is similar to the following example:
Removing objects: Removing gs://example-bucket/file.txt... Completed 1/1
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage C# API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Go API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Java API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Node.js API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
C++
C#
Go
Java
Node.js