The gcloud command-line tool cheat sheet

The gcloud cheat sheet

A roster of go-to gcloud commands for the gcloud tool, Google Cloud's primary command-line tool.

(Also included: introductory primer, understanding commands, and a printable PDF.)

Cheat sheet

Getting started

Get going with the gcloud command-line tool.

Help

Cloud SDK is happy to help.

  • gcloud help: Search the gcloud tool reference documents for specific terms.
  • gcloud feedback: Provide feedback for the Cloud SDK team.
  • gcloud topic: Supplementary help material for non-command topics like accessibility, filtering, and formatting.

Personalization

Make the Cloud SDK your own; personalize your configuration with properties.

Credentials

Grant and revoke authorization to Cloud SDK

Projects

Manage project access policies

Identity & Access Management

Configuring Cloud Identity & Access Management (IAM) preferences and service accounts

Docker & Google Kubernetes Engine (GKE)

Manage containerized applications on Kubernetes

Virtual Machines & Compute Engine

Create, run, and manage VMs on Google infrastructure

Serverless & App Engine

Build highly scalable applications on a fully managed serverless platform

Miscellaneous

Commands that might come in handy

Introductory primer

A quick primer for getting started with the gcloud command-line tool.

Installing the Cloud SDK

Install the Cloud SDK with these installation instructions.

Flags, arguments, and other wondrous additions

Arguments can be Positional args or Flags

  • Positional args: Set after command name; must respect order of positional args.
  • Flags: Set after positional args; order of flags doesn't matter.

    A flag can be either a:

    • Name-value pair (--foo=bar), or
    • Boolean (--force/no-force).

    Additionally, flags can either be:

    • Required
    • Optional: in which case, the default value is used, if the flag is not defined

Global flags

Some flags are available throughout the gcloud command-line tool experience, like:

  • --help: For when in doubt; display detailed help for a command.
  • --project: If using a project other than the current one.
  • --quiet: Disabling interactive prompting (and appl
  • --verbosity: Can set verbosity levels at debug, info, warning, error, critical, and none.
  • --version: Display gcloud version information.
  • --format: Set output format as config, csv, default, diff, disable, flattened, get, json, list, multi, none, object, table, text, value, or yaml.

Cleaning up results

Extricate the most from your output with the filter, format, limit, and sort-by flags.

For Compute Engine instances with prefix us and not machine type f1-micro:

For a list of projects created on or after 15 January 2018, sorted from oldest to newest, presented as a table with project number, project id and creation time columns with dates and times in local timezone:

For a list of ten Compute Engine instances with a label my-label (of any value):

Understanding commands

The underlying patterns for gcloud commands; to aid self-discovery of commands.

Finding gcloud commands

The gcloud command-line tool is a tree; non-leaf nodes are command groups and leaf nodes are commands. (Also, tab completion works for commands and resources!)

Most gcloud commands follow the following format:

For example: gcloud + compute + instances + create + example-instance-1 + --zone=us-central1-a

Release level

Release Level refers to the command's release status.

Example: alpha for alpha commands, beta for beta commands, no release level needed for GA commands.

Component

Component refers to the different Google Cloud services.

Example: compute for Compute Engine, app for App Engine, etc.

Entity

Entity refers to the plural form of an element or collection of elements under a component.

Example: disks, firewalls, images, instances, regions, zones for compute

Operation

Operation refers to the imperative verb form of the operation to be performed on the entity.

Example: Common operations are describe, list, create/update, delete/clear, import, export, copy, remove, add, reset, restart, restore, run, and deploy.

Positional args

Positional args refer to the required, order-specific arguments needed to execute the command.

Example: <INSTANCE_NAMES> is the required positional argument for gcloud compute instances create.

Flags

Flags refer to the additional arguments, --flag-name(=value), passed in to the command after positional args.

Example: --machine-type=<MACHINE_TYPE> and --preemptible are optional flags for gcloud compute instances create.