Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



rm - Remove objects

rm - Remove objects

Synopsis

gsutil rm [-f] [-R] url...

Description

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 a parallel (multi-threaded/multi-processing) removes:

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

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.

Options

-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. This option is implicitly set when running “gsutil -m rm ...”.
-R , -r 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. The -r flag implies the -a flag and will delete all object versions.
-a Delete all versions of an object.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.