建議使用 Google Cloud CLI 指令列工具與 Cloud Storage 互動。本頁面說明 gsutil 和 gcloud CLI 的 gcloud storage 指令之間的主要差異和指令對應關係,協助您從前者轉換至後者。如果您的指令碼使用 gsutil,可以參考本頁資訊,改用對應的 gcloud storage 指令更新指令碼。
如要瞭解如何開始使用 gcloud CLI,請參閱「安裝 Google Cloud CLI」。
如需 gcloud storage 指令的詳細說明,請參閱 gcloud storage 參考文件。
行為差異
以下各節說明 gsutil 和 gcloud storage 的行為差異。
平行叫用
gcloud storage 不支援在同一部機器上使用多個終端機平行叫用。
平行處理
gcloud storage 支援平行處理。
萬用字元處理
gcloud storage 會簡化多個星號。如果連續使用三個以上的星號 (***),系統會將其視為單一星號 (*)。
處理階層命名空間 bucket
gcloud storage 可用於建立及管理已啟用階層命名空間的 bucket。
支援本機到本機的檔案複製作業
gcloud storage 專門用於與 Cloud Storage 互動,不支援本機到本機的檔案複製作業。如要使用 gcloud storage 成功移動資料,至少須有一個引數 (來源或目的地) 為 Cloud Storage 資源 URI。例如:gs://my-bucket。
輸出格式
gcloud storage 和 gsutil 指令的輸出格式不同。
雖然記錄格式等細微變更可能不會影響您,但錯誤訊息和資料清單中的重大差異可能會破壞自動化指令碼。
如果您有依賴剖析 gsutil 指令輸出的指令碼,請先檢查並更新這些指令碼,使其符合 gcloud storage 格式,再進行轉換。
等效的 gcloud 指令
除了少數例外狀況,所有現有的 gsutil 指令在 gcloud storage 中都有對應的指令。如要取得 gcloud storage 指令的完整清單,請參閱參考文件或執行 gcloud storage --help。下表簡要說明常用 gsutil 指令的異動。
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 管理存取控制清單 (ACL) |
gsutil acl get gsutil acl set gsutil acl ch |
gcloud storage RESOURCE describe --format="multi(acl:format=json)" gcloud storage RESOURCE update --acl-file=ACL_FILE_PATH gcloud storage RESOURCE update --add-acl-grant=GRANT gcloud storage RESOURCE update --remove-acl-grant=GRANT |
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 串連物件並顯示物件內容 |
gsutil cat |
gcloud storage cat |
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 將物件合併為新物件,藉此串連物件 |
gsutil compose |
gcloud storage objects compose |
附註如要在gcloud storage objects compose 中套用前置條件,請使用特定旗標,例如 --if-generation-match 或 --if-metageneration-match。 |
||
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 複製物件和其他資源 |
gsutil cp |
gcloud storage cp |
附註使用 Google Cloud 控制台建立的模擬資料夾會視為 0 位元組的預留位置物件。 處理錯誤時, 下載物件時, |
||
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 顯示物件使用的磁碟空間總量 |
gsutil du |
gcloud storage du |
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 計算檔案雜湊值 |
gsutil hash |
gcloud storage hash |
附註
|
||
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 管理 bucket 標籤 |
gsutil label get gsutil label set gsutil label ch |
gcloud storage buckets describe gcloud storage buckets update gcloud storage buckets update |
附註在單一 |
||
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 列出 bucket、物件和資料夾 |
gsutil ls |
gcloud storage ls |
附註使用萬用字元列出專案中的物件時, 使用
|
||
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 移動及重新命名物件或目錄 |
gsutil mv |
gcloud storage mv |
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 就地重寫物件 |
gsutil rewrite |
gcloud storage objects update |
附註如果 boto 設定檔中已設定
|
||
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 移除物件或 bucket |
gsutil rm |
gcloud storage rm |
附註不支援 目前已知 |
||
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 同步處理兩個 bucket 或目錄的內容 |
gsutil rsync |
gcloud storage rsync |
附註根據預設,如果來源和目的地的物件大小和上次修改時間相符,
|
||
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 為上傳的物件設定中繼資料 |
gsutil setmeta |
gcloud storage objects update |
附註
在 |
||
| 作業 | gsutil 指令 | gcloud storage 指令 |
|---|---|---|
| 顯示物件狀態 |
gsutil stat |
gcloud storage objects list --stat --fetch-encrypted-object-hashes |
附註
|
||
後續步驟
如要進一步瞭解指令和旗標對應,請參閱 gsutil GitHub 存放區中的遷移參考資料。