Quick cleaning of GCP projects from the command line

Emanuele Pecorari
1 min readMay 21, 2022

The GCP user interface is quite cool and really usable but some operations can be done without going on it and often, it can be faster.

Let’s see for example how quickly we can see the projects in our GCP account and choose some to delete

List the projects

First, it’s possible to have an overview of the projects with the following command (supposing the authentication for the GCP CLI is already one):

gcloud projects list

that will give something like this:

PROJECT_ID          NAME            PROJECT_NUMBER
mercurial-idiom-728 LoopbackPush YYYYYYYYYYYY
voiceroutertest VoiceRouterTest ZZZZZZZZZZZZ

Delete a project

Now, using the PROJECT_NUMBER value, we can delete a project:

gcloud projects delete <PROJECT_NUMBER>

A confirmation will be asked.

Recover a delete project

In case we delete a project mistakenly, there are 30 days to have it back. It’s possible to list the projects for which the deletion has been requested:

gcloud projects list — filter=’lifecycleState:DELETE_REQUESTED’

and then, using again the PROJECT_NUMBER:

gcloud projects undelete <PROJECT_NUMBER>

the project can be recovered.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Emanuele Pecorari
Emanuele Pecorari

Written by Emanuele Pecorari

Cloud Architect and Tech Product Owner. Soccer player and coach in the free time.

No responses yet

Write a response