label - Get, set, or change the label configuration of a bucket.

label - Get, set, or change the label configuration of a bucket.

Synopsis

gsutil label set label-json-file url... gsutil label get url gsutil label ch <label_modifier>... url

where each <label_modifier> is one of the following forms:

-l <key>:<value>
-d <key>

Description

Gets, sets, or changes the label configuration (also called the tagging configuration by other storage providers) of one or more buckets. An example label JSON document looks like the following:

{
  "your_label_key": "your_label_value",
  "your_other_label_key": "your_other_label_value"
}

The label command has three sub-commands:

Get

The "label get" command gets the labels applied to a bucket, which you can save and edit for use with the "label set" command.

Set

The "label set" command allows you to set the labels on one or more buckets. You can retrieve a bucket's labels using the "label get" command, save the output to a file, edit the file, and then use the "label set" command to apply those labels to the specified bucket(s). For example:

gsutil label get gs://bucket > labels.json

Make changes to labels.json, such as adding an additional label, then:

gsutil label set labels.json gs://example-bucket

Note that you can set these labels on multiple buckets at once:

gsutil label set labels.json gs://bucket-foo gs://bucket-bar

Ch

The "label ch" command updates a bucket's label configuration, applying the label changes specified by the -l and -d flags. You can specify multiple label changes in a single command run; all changes will be made atomically to each bucket.

Ch Examples

Examples for "ch" sub-command:

Add the label "key-foo:value-bar" to the bucket "example-bucket":

gsutil label ch -l key-foo:value-bar gs://example-bucket

Change the above label to have a new value:

gsutil label ch -l key-foo:other-value gs://example-bucket

Add a new label and delete the old one from above:

gsutil label ch -l new-key:new-value -d key-foo gs://example-bucket

Ch Options

The "ch" sub-command has the following options:

-l Add or update a label with the specified key and value.
-d Remove the label with the specified key.

Send feedback about...

Cloud Storage Documentation