How to Get the Default GCP Project ID with a Cloud SDK CLI One-Liner

To get the default Google Cloud Platform (GCP) project ID using the Cloud SDK Command Line Interface (CLI) in a one-liner, use this command: gcloud config list –format ‘value(core.project)’ 2>/dev/null

This command lists the gcloud configuration properties and filters the output to display only the project ID.

  1. The –format ‘value(core.project)’ flag specifies that you want to extract the value of the core.project property.
  2. The 2>/dev/null part suppresses any error messages to keep the output clean.

You can also use this command.

gcloud config get-value project

This command will return the project ID currently set as the default in your gcloud configuration. If no default project is set, the command will return an empty value.

That’s it.

Leave a Comment