This cheatsheet provides a quick reference for essential Google Cloud Platform (GCP) commands using the gcloud and gsutil tools. Master these commands to efficiently manage your cloud resources.
Check Version and Settings:gcloud version,gcloud info,gcloud components listInitialize GCP SDK Profile:gcloud init(This command will guide you through setting up your project and authentication.)List all available zones:gcloud compute zones listUpgrade local SDK components:gcloud components update, or specify a version:gcloud components update --version 219.0.1
List buckets and files:gsutil ls, or for detailed listing:gsutil ls -lh gs://<bucket-name>Download a file from a bucket:gsutil cp gs://<bucket-name>/<dir-path>/package-1.1.tgz .Upload a file to a bucket:gsutil cp <filename> gs://<bucket-name>/<directory>/View file content:gsutil cat gs://<bucket-name>/<filepath>/Delete a file from a bucket:gsutil rm gs://<bucket-name>/<filepath>Move or rename a file/object:gsutil mv <src-filepath> gs://<bucket-name>/<directory>/<dest-filepath>Copy an entire folder recursively:gsutil cp -r ./conf gs://<bucket-name>/Show disk usage for a bucket/directory:gsutil du -h gs://<bucket-name>/<directory>/Create a new bucket:gsutil mb gs://<bucket-name>Calculate file SHA1 checksum:gsha1sum <filename>, orshasum <filename>Access gsutil help documentation:gsutil help,gsutil help cp,gsutil help options
List current project configuration:gcloud config list, or specifically for project:gcloud config list projectShow project information:gcloud compute project-info describeSwitch to a different project:gcloud config set project <project-id>
Display a list of authenticated accounts:gcloud auth listSet the active account for gcloud:gcloud config set account <ACCOUNT>Configure kubectl context for a GKE cluster:gcloud container clusters get-credentials <cluster-name>Change the default compute region:gcloud config set compute/region us-westChange the default compute zone:gcloud config set compute/zone us-west1-bList all GKE container clusters:gcloud container clusters list
Authenticate using a service account key file:gcloud auth activate-service-account --key-file <key-file>Display a list of credentialed accounts:gcloud auth listSet the active account for gcloud:gcloud config set account <ACCOUNT>Configure Docker authentication for GCP Container Registry:gcloud auth configure-dockerPrint the access token for the active account:gcloud auth print-access-token, or refresh token:gcloud auth print-refresh-tokenRevoke previously generated credentials:gcloud auth application-default revoke
Make all files in a bucket publicly readable:gsutil -m acl set -R -a public-read gs://<bucket-name>/Configure gsutil authentication:gsutil config -aGrant specific IAM roles to a user for a bucket:gsutil iam ch user:[email protected]:objectCreator,objectViewer gs://<bucket-name>Remove IAM roles from a user for a bucket:gsutil iam ch -d user:[email protected]:objectCreator,objectViewer gs://<bucket-name>
List all VM instances:gcloud compute instances list, or instance templates:gcloud compute instance-templates listShow detailed information about a VM instance:gcloud compute instances describe "<instance-name>" --project "<project-name>" --zone "us-west2-a"Stop a VM instance:gcloud compute instances stop instance-2Start a VM instance:gcloud compute instances start instance-2Create a new VM instance:gcloud compute instances create vm1 --image image-1 --tags test --zone "<zone>" --machine-type f1-microSSH into a VM instance:gcloud compute ssh --project "<project-name>" --zone "<zone-name>" "<instance-name>"Download files from a VM instance:gcloud compute copy-files example-instance:~/REMOTE-DIR ~/LOCAL-DIR --zone us-central1-aUpload files to a VM instance:gcloud compute copy-files ~/LOCAL-FILE-1 example-instance:~/REMOTE-DIR --zone us-central1-a
List all persistent disks:gcloud compute disks listList all available disk types:gcloud compute disk-types listList all disk snapshots:gcloud compute snapshots listCreate a snapshot of a disk:gcloud compute disks snapshot <diskname> --snapshotname <name1> --zone $zone
List all VPC networks:gcloud compute networks listGet detailed information about a network:gcloud compute networks describe <network-name> --format jsonCreate a new VPC network:gcloud compute networks create <network-name>Create a subnet within a network:gcloud compute networks subnets create subnet1 --network net1 --range 10.5.4.0/24Reserve a static external IP address:gcloud compute addresses create --region us-west2-a vpn-1-static-ipList all reserved IP addresses:gcloud compute addresses listDescribe a specific IP address resource:gcloud compute addresses describe <ip-name> --region us-central1List all network routes:gcloud compute routes list
List all record-sets in a managed zone:gcloud dns record-sets list --zone my_zoneList the first 10 DNS records in a zone:gcloud dns record-sets list --zone my_zone --limit=10
List all firewall rules:gcloud compute firewall-rules listList all forwarding rules:gcloud compute forwarding-rules listDescribe a specific firewall rule:gcloud compute firewall-rules describe <rule-name>Create a new firewall rule:gcloud compute firewall-rules create my-rule --network default --allow tcp:9200 tcp:3306Update an existing firewall rule:gcloud compute firewall-rules update default --network default --allow tcp:9200 tcp:9300
List all available images:gcloud compute images listList all GKE container clusters:gcloud container clusters listSet kubectl context for a GKE cluster:gcloud container clusters get-credentials <cluster-name>
List all Cloud SQL instances:gcloud sql instances list
List all backend services:gcloud compute backend-services listList all health check endpoints:gcloud compute http-health-checks listList all URL maps:gcloud compute url-maps list
For more detailed information and advanced usage, refer to the official gcloud CLI documentation and gsutil documentation.