rm - Remove objects


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


The gsutil rm command removes objects and/or buckets. 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


-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 deletes the bucket. This option implies the -a option and deletes all object versions. If you only want to delete live object versions, use the '**' wildcard instead of -r.
-a Delete all versions of an object.