rm - Remove objects

rm - Remove objects


gsutil rm [-f] [-r] url... gsutil rm [-f] [-r] -I


The gsutil rm command removes objects. For example, the command:

gsutil rm gs://bucket/subdir/*

will remove all objects in gs://bucket/subdir, but not in any of its sub-directories. In contrast:

gsutil rm gs://bucket/subdir/**

will remove all objects under gs://bucket/subdir or any of its subdirectories.

You can also use the -r option to specify recursive object deletion. Thus, for example, either of the following two commands will remove gs://bucket/subdir and all objects and subdirectories under it:

gsutil rm gs://bucket/subdir**
gsutil rm -r gs://bucket/subdir

The -r option will also delete all object versions in the subdirectory for versioning-enabled buckets, whereas the ** command will only delete the live version of each object in the subdirectory.

Running gsutil rm -r on a bucket will delete all versions of all objects in the bucket, and then delete the bucket:

gsutil rm -r gs://bucket

If you want to delete all objects in the bucket, but not the bucket itself, this command will work:

gsutil rm gs://bucket/**

If you have a large number of objects to remove you might want to use the gsutil -m option, to perform parallel (multi-threaded/multi-processing) removes:

gsutil -m rm -r gs://my_bucket/subdir

You can pass a list of URLs (one per line) to remove on stdin instead of as command line arguments by using the -I option. This allows you to use gsutil in a pipeline to remove objects identified by a program, such as:

some_program | gsutil -m rm -I

The contents of stdin can name cloud URLs and wildcards of cloud URLs.

Note that gsutil rm will refuse to remove files from the local file system. For example this will fail:

gsutil rm *.txt

WARNING: Object removal cannot be undone. Google Cloud Storage is designed to give developers a high amount of flexibility and control over their data, and Google maintains strict controls over the processing and purging of deleted data. To protect yourself from mistakes, you can configure object versioning on your bucket(s). See gsutil help versions for details.

Data Restoration From Accidental Deletion Or Overwrites

Google Cloud Storage does not provide support for restoring data lost or overwritten due to customer errors. If you have concerns that your application software (or your users) may at some point erroneously delete or overwrite data, you can protect yourself from that risk by enabling Object Versioning (see gsutil help versioning). Doing so increases storage costs, which can be partially mitigated by configuring Lifecycle Management to delete older object versions (see gsutil help lifecycle).


-f Continues silently (without printing error messages) despite errors when removing multiple objects. If some of the objects could not be removed, gsutil's exit status will be non-zero even if this flag is set. Execution will still halt if an inaccessible bucket is encountered. This option is implicitly set when running "gsutil -m rm ...".
-I Causes gsutil to read the list of objects to remove from stdin. This allows you to run a program that generates the list of objects to remove.
-R, -r The -R and -r options are synonymous. Causes bucket or bucket subdirectory contents (all objects and subdirectories that it contains) to be removed recursively. If used with a bucket-only URL (like gs://bucket), after deleting objects and subdirectories gsutil will delete the bucket. This option implies the -a option and will delete all object versions.
-a Delete all versions of an object.

Send feedback about...

Cloud Storage Documentation