gcloud storage(正式版)是建议用于与 Cloud Storage 交互的命令行工具。本页面通过介绍两种工具之间的主要差异和命令映射,来帮助您从 gsutil 过渡到 gcloud storage。如需详细了解 gcloud storage 工具,请参阅 gcloud storage 参考文档。
如需了解如何安装并开始使用 Google Cloud CLI,请参阅安装 Google Cloud CLI。
行为差异
以下部分介绍了 gsutil 和 gcloud storage 之间的行为差异。
并行调用
gcloud storage 不支持同时从不同终端运行 CLI 的多个实例。
并行处理
gcloud storage 支持并行处理。
通配符处理
gcloud storage 会简化多个星号。如果您连续使用三个或更多星号 (***),该工具会将它们视为一个星号 (*)。
分层命名空间存储桶的处理
gcloud storage 可用于创建和管理启用了分层命名空间的存储桶。
输出格式
gcloud storage 和 gsutil 命令的输出格式不同。虽然日志记录格式等细微更改可能不会对您造成影响,但错误消息和数据列表中的更显著差异可能会破坏自动化脚本。
如果您具有依赖于解析 gsutil 命令输出的脚本,则应在转换这些脚本之前,先查看并更新它们以适应 gcloud storage 格式。
等效的 gcloud 命令
除了少数几个例外,所有现有的 gsutil 命令在 gcloud storage 中都有等效的命令。您可以访问参考文档或运行 gcloud storage --help 以获得完整的 gcloud storage 命令列表。下表简要概述了常用 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 命令 |
|---|---|---|
| 管理存储桶标签 |
gsutil label get gsutil label set gsutil label ch |
gcloud storage buckets describe gcloud storage buckets update gcloud storage buckets update |
备注在单个 |
||
| 操作 | gsutil 命令 | gcloud storage 命令 |
|---|---|---|
| 列出存储桶、对象和文件夹 |
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 命令 |
|---|---|---|
| 移除对象或存储桶 |
gsutil rm |
gcloud storage rm |
备注不支持 存在一个已知问题,即当 |
||
| 操作 | gsutil 命令 | gcloud storage 命令 |
|---|---|---|
| 同步两个存储桶或目录的内容 |
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 仓库中的迁移参考。