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 following command removes the object
gsutil rm gs://bucket/kitten.png
Use the -r option to specify recursive object deletion. For example, the following command removes gs://bucket/subdir and all objects and subdirectories under it:
gsutil rm -r gs://bucket/subdir
When working with versioning-enabled buckets, note that the -r option removes all object versions in the subdirectory. To remove only the live version of each object in the subdirectory, use the ** wildcard.
The following command removes all versions of all objects in a bucket, and then deletes the bucket:
gsutil rm -r gs://bucket
To remove all objects and their versions from a bucket without deleting the
bucket, use the
gsutil rm -a gs://bucket/**
If you have a large number of objects to remove, use the
gsutil -m option,
which enables multi-threading/multi-processing:
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.
gsutil rm refuses to remove files from the local file system.
For example, this fails:
gsutil rm *.txt
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 ...".
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.
Delete all versions of an object.