安装 gcloud
gcloud 是 Google Cloud 的命令行工具。
安装
Ubuntu
# 导入 GPG 公钥
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
# 添加软件源
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
# 更新软件包索引
sudo apt update
# 安装 gcloud CLI
sudo apt install google-cloud-cli
初始化:
gcloud init
你将被提示使用浏览器打开登录链接并选择一个 Google Cloud 项目。
macOS
前往官网安装最新的 gcloud CLI 版本,下载适合你系统的安装包。
解压安装包并进入解压目录,然后运行:
# 安装
./google-cloud-sdk/install.sh
# 初始化
./google-cloud-sdk/bin/gcloud init
打开一个新的终端窗口以便配置生效。
Linux
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-linux-x86_64.tar.gz
tar -zxf google-cloud-cli-linux-x86_64.tar.gz -C ~/.local/opt && rm google-cloud-cli-linux-x86_64.tar.gz
~/.local/opt/google-cloud-sdk/install.sh
卸载
rm -rf $(gcloud info --format='value(config.paths.global_config_dir)')
rm -rf $(gcloud info --format='value(installation.sdk_root)')
find ~/Library/Caches/ -type d -name "google-cloud-sdk" | xargs rm -r
编辑 ~/.bashrc,删掉下面两行:
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/xiao/Downloads/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/xiao/Downloads/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/xiao/Downloads/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/xiao/Downloads/google-cloud-sdk/completion.zsh.inc'; fi
编辑 ~/.boto,删掉 [GoogleCompute] 和 [GSUtil] 节的全部内容,以及 [OAuth2] 和 [Credentials] 节的无用设置。
卸载 Google Cloud CLI | Google Cloud CLI Documentation
使用
gcloud
# 未完待续
gsutil
gsutil ls gs://bucket-name/dir # 列出存储桶内容
gsutil cp -r "gs://bucket-name/dir/*" /local/dir # 拷贝文件
gsutil rsync -r gs://bucket-name/dir /local/dir # 使用 rsync
rsync 支持 -r(递归)和 -d(删除多余文件)选项。

浙公网安备 33010602011771号