gcloud
gcloud 480+gcloud(Google Cloud CLI)、gsutil、bq 命令快速參考:驗證、project/IAM、Compute/GKE/BigQuery/Cloud Storage、設定、Cloud Build/Deploy——附常用參數與實作範例。
48 條命令
說明
gcloud --version印出 gcloud、gsutil、bq 與核心函式庫的版本。
gcloud --versiongcloud help顯示頂層說明與完整指令群組列表。
gcloud helpgcloud help <cmd>顯示任何 gcloud 指令的旗標與範例(路徑分隔符為空白)。
gcloud help compute instances creategcloud topic <topic>閱讀深入文件:`configurations`、`projections`、`filters`、`offline` 等。
configurations;projections;filters;offline;access-control
gcloud topic filters驗證
gcloud init首次執行精靈——登入、選擇專案、選擇預設 region/zone。
gcloud initgcloud auth login授權 gcloud 以你的使用者憑證存取 GCP(瀏覽器 OAuth 流程)。
--no-launch-browser;--no-activate
gcloud auth login --no-launch-browsergcloud auth application-default login設定 Application Default Credentials——供用戶端函式庫(Python/Node/Go)使用。
--scopes <scope1,scope2>;--no-launch-browser
gcloud auth application-default logingcloud auth activate-service-account --key-file <key.json>使用下載的 JSON key 檔啟用 service account。
gcloud auth activate-service-account [email protected] --key-file=ci.jsongcloud auth list列出所有已認證的帳號。
--format=yaml;--filter
gcloud auth listgcloud auth revoke撤銷一個或所有帳號的憑證。
<account>;--all
gcloud auth revoke --all專案
gcloud config get-value project印出當前使用中的專案。
gcloud config get-value projectgcloud config set project <id>設定使用中的專案。
gcloud config set project my-gcp-projectgcloud projects list列出你有權存取的所有專案。
--format='table(projectId,name,projectNumber)';--limit
gcloud projects list --format='table(projectId,name)'設定
gcloud config configurations list列出所有已儲存的設定(具名 profile)。
--format=yaml
gcloud config configurations listgcloud config configurations create <name>建立新的具名設定。
--no-activate
gcloud config configurations create dev --no-activategcloud config configurations activate <name>切換到既有設定。
gcloud config configurations activate prodCLOUDSDK_ACTIVE_CONFIG_NAME=<name> gcloud ... 使用某個設定而不修改持久化設定(CI/腳本)。
CLOUDSDK_ACTIVE_CONFIG_NAME=prod gcloud compute instances listgcloud config set compute/region <region>為特定屬性設定預設值(region/zone/project/account)。
compute/region;compute/zone;container/cluster;compute/region us-central1
gcloud config set compute/region us-central1輸出
gcloud <cmd> --format=<fmt>選擇輸出格式:`json`、`yaml`、`table`、`csv`、`value`、`default`。
json;yaml;table;csv;value;default;get(<expr>):label
gcloud compute instances list --format='table(name,zone.basename(),machineType.basename())'gcloud <cmd> --filter='<expr>'伺服器端過濾——運算式語法請參閱 `gcloud topic filters`。
name=foo;zone:us-*;status:RUNNING
gcloud compute instances list --filter='zone:us-central1-a AND labels.env=prod'gcloud <cmd> --limit <N>限制回傳筆數(伺服器端分頁否則無上限)。
gcloud compute instances list --limit=20IAM
gcloud iam service-accounts list列出當前專案中的所有 service account。
--project;--format=json;--limit
gcloud iam service-accounts listgcloud iam service-accounts keys create <file.json> --iam-account <sa>為 service account 建立 JSON key——不支援 ADC 的工具需要。
--iam-account <sa>;--key-file-type json
gcloud iam service-accounts keys create ci.json --iam-account [email protected]gcloud projects add-iam-policy-binding <project> --member='user:<email>' --role='roles/<role>'在專案層級把角色授予成員。
--member=user:foo@bar / serviceAccount:foo / group:bar / domain:bar;--role=roles/owner
gcloud projects add-iam-policy-binding my-proj --member='user:[email protected]' --role='roles/viewer'Compute Engine
gcloud compute instances list列出所有 VM 及其 zone、機器類型與狀態。
--project;--filter;--format=table;--limit
gcloud compute instances list --format='table(name,zone,machineType,status)'gcloud compute instances create <name> --zone <z> --machine-type <t>以預設映像(Debian 12)建立 VM。
--zone;--machine-type;--image-family;--image-project;--preemptible;--tags;--labels;--metadata;--service-account;--scopes
gcloud compute instances create vm-dev --zone=us-central1-a --machine-type=e2-medium --image-family=debian-12gcloud compute ssh <vm> --zone <z>對 VM 開啟 SSH 工作階段(會在 `~/.ssh/google_compute_engine` 下自動產生/保存金鑰)。
--zone;--ssh-key-file;--command <cmd>;--tunnel-through-iap;--internal-ip
gcloud compute ssh vm-dev --zone=us-central1-a --command 'docker ps'gcloud compute instances delete <vm> --zone <z>刪除 VM(可選擇是否連同磁碟)。
--zone;--delete-disks=all / data / boot
gcloud compute instances delete vm-dev --zone=us-central1-a --delete-disks=allgcloud compute disks list列出所有持久磁碟。
--filter='zone:us-*';--format=table
gcloud compute disks list --format='table(name,sizeGb,zone,status)'gcloud compute snapshots create <name> --source-disk <disk>為持久磁碟建立 snapshot 以備份或複製。
--source-disk <name>;--source-disk-zone;--description
gcloud compute snapshots create snap-2026-08-25 --source-disk=data-disk --source-disk-zone=us-central1-aGKE
gcloud container clusters list列出所有 GKE 叢集。
--region;--format=table;--limit
gcloud container clusters list --format='table(name,zone,masterVersion,status)'gcloud container clusters get-credentials <name> --region <r>把叢集的 kubeconfig 合併到 `~/.kube/config` 並切換 context。
--region;--zone;--project;--internal-ip
gcloud container clusters get-credentials my-cluster --region=us-central1gcloud container clusters create <name> --num-nodes=1建立 Autopilot 或 Standard GKE 叢集。
--num-nodes;--machine-type;--region;--enable-autoscaling;--enable-autorepair;--cluster-version;--release-channel rapid|regular|stable
gcloud container clusters create my-cluster --region=us-central1 --num-nodes=3 --enable-autoscaling --min-nodes=1 --max-nodes=5Cloud Storage
gsutil ls列出 bucket/物件(別名:`gcloud storage ls`)。
-r;-l;-h;gs://;-d(只列目錄)
gsutil ls gs://my-bucket/data/gsutil cp <local> gs://<bucket>/<key>上傳或複製物件。`-r` 用於遞迴複製目錄。
-r;-m 平行;-c 保留 cache-control;-p 保留 ACL;-n 不覆寫;-z <fmt> 上傳時壓縮
gsutil cp -r ./dist gs://my-bucket/app/gsutil rsync -r <src> <dst>雙向目錄同步(平行、快速)。來源/目的地可以是本地或 `gs://`。
-r;-d 刪除多餘項目;-c 以校驗碼比對;-n 試跑;-x 排除
gsutil rsync -r -d ./build gs://my-bucket/buildgcloud storage buckets create gs://<name> --location <loc>建立新的 Cloud Storage bucket,可指定 location/class。
--location;--default-storage-class;--uniform-bucket-level-access;--public-access-prevention
gcloud storage buckets create gs://my-bucket --location=us-central1 --uniform-bucket-level-accessBigQuery
bq query --use_legacy_sql=false 'SELECT ...'對 BigQuery 執行臨時 SQL 查詢。
--use_legacy_sql=false;--max_rows;--destination_table;--parameter;--format=json
bq query --use_legacy_sql=false 'SELECT COUNT(*) FROM `bigquery-public-data.samples.shakespeare`'bq show --format=pretty <project>:<dataset>顯示專案/資料集/資料表/工作的 metadata。
--format=pretty;--schema;--view
bq show my-proj:my_datasetbq load --source_format=CSV --autodetect <dataset>.<table> <file>把本地 CSV/JSON/Parquet 檔案批次載入到 BigQuery 資料表。
--source_format=CSV|JSON|PARQUET|AVRO|NEWLINE_DELIMITED_JSON;--autodetect;--replace;--skip_leading_rows=1
bq load --source_format=CSV --autodetect --skip_leading_rows=1 my_dataset.users users.csvCloud Build
gcloud builds submit --tag gcr.io/<proj>/<img>使用預設 Cloud Build 設定,從當前目錄建置容器。
--tag;--config <file>;--machine-type;--timeout;--gcs-source-staging-dir;--no-source-image-upload
gcloud builds submit --tag gcr.io/my-proj/app:v1 .Cloud Deploy
gcloud app deploy <yaml>部署到 App Engine standard/flex。
--image-url;--version;--promote;--stop-previous-version
gcloud app deploy app.yaml --promotePub/Sub
gcloud pubsub topics publish <topic> --message '<msg>'發布單一訊息——適合臨時測試。
--message;--attributes;--ordering-key
gcloud pubsub topics publish my-topic --message 'hello' --attributes=k=vgcloud pubsub subscriptions pull <sub> --limit <N> --auto-ack從 subscription 拉取(並自動 ack)N 條訊息——健全性檢查很實用。
--limit;--auto-ack;--format=json
gcloud pubsub subscriptions pull my-sub --limit=5 --auto-ack部署/回滾
gcloud components update把 gcloud 本身與所有已安裝 component 更新到最新版本。
gcloud components updategcloud components install <name>安裝可選的 gcloud component(kubectl、bq、gsutil、app-engine-python 等)。
<name>
gcloud components install kubectl診斷
gcloud info印出 gcloud 環境:python 版本、安裝位置、當前設定。
--run-diagnostics;--log-level=debug
gcloud infogcloud feedback在瀏覽器中開啟公開的 gcloud issue tracker,並預先填入環境資訊。
--log-level=debug
gcloud feedback相關命令速查
aws cli
AWS Command Line Interface 命令快速參考:設定憑證、IAM 身分、EC2/Lambda/S3/DynamoDB/IAM、profiles、SSO,以及分頁/輸出格式化——附常用參數與實作範例。
40 條命令
AWS CLI v2
azure cli
Azure CLI(az)命令快速參考:驗證、subscription/資源管理、VM/AKS/Storage/App Service/Key Vault、query 格式化、CI 友善工作流——附常用參數與實作範例。
43 條命令
Azure CLI 2.60+
kubectl
kubectl(Kubernetes 命令列工具)快速參考:context、get/describe、apply、logs/exec、rollout、scaling 及除錯——附常用參數與實作範例。
40 條命令
kubectl 1.28+
docker
日常高頻 Docker CLI 命令快速參考:容器生命週期、映像檔建置、日誌 / exec、網絡、磁碟區、Compose、Registry 與系統清理——附常用參數與實作範例。
46 條命令
Docker Engine 24.0+
商標與使用聲明
本批命令列工具速查手冊為開源社群參考資料。文中涉及的各工具的名稱、標識、商標(如 Git™、Docker™、Kubernetes®、kubectl、PostgreSQL®、MySQL®、Redis™、MongoDB®、Linux™、PowerShell™、Vim™ 等)均歸對應權利人所有,此處僅為識別與參考之目的使用。
本速查手冊的全部內容均為獨立編寫的簡化自包含參考,**與任何官方文件不存在隸屬、被認可或引用關係**。命令列表、參數說明、範例均為作者原創簡化表達;如需權威資訊,請參閱各工具的官方文件。
命令語法與參數可能在不同工具版本中有所差異。所示版本標籤對應穩定發佈版本;其他版本行為可能有所不同。本速查手冊**不代表**商標權利人的任何偏好或推薦。
如商標或版權方認為本站部分內容存在權益侵害,請發送電郵至[email protected],我們在收到有效權屬證明後,會在合理期限內修改或移除相關內容。
本網站不對因使用本站資訊而產生的任何直接或間接損失承擔法律責任。
關於 Google Cloud CLI
Google Cloud CLI(gcloud)是 Google 官方的命令列工具,用於管理 Google Cloud Platform(GCP)服務。它在一個安裝檔中綑綁三個執行檔:`gcloud`(資源管理、IAM、App Engine、Cloud SQL、GKE、Compute Engine)、`gsutil`(Cloud Storage,最初來自較舊的獨立 `gsutil` CLI)、`bq`(BigQuery)。目前穩定版線為 gcloud 480+(2025 年 8 月時代)。gcloud 遵循資源群組模式:`gcloud <group> <resource> <verb>`——例如 `gcloud compute instances list`、`gcloud iam service-accounts keys create`。驗證支援互動式 `gcloud auth login`、service-account key,以及透過 `gcloud auth application-default login` 取得的 Application Default Credentials(ADC)——後者是 Terraform、Python 與 Node.js SDK 的標準憑證來源。gcloud 以 Apache 2.0 授權,除了明確的 `gcloud app deploy`、`gcloud builds submit` 等之外,不會上傳你的程式碼到任何地方。
速查頁版本 1.0.0