Gsutil - 如何使用Gsutil检查GCS存储桶(子目录)中是否存在文件

问题描述 投票:7回答:3

我有一个GCS存储桶包含路径中的一些文件

GS://main-bucket/sub-directory-bucket/object1.gz

我想以编程方式检查子目录存储桶是否包含一个特定文件。我想用gsutil来做这件事。

怎么可以这样做?

python google-cloud-storage gsutil
3个回答
6
投票

您可以使用gsutil stat命令。


2
投票

使用gsutil stat命令。要访问具有更多文件数的子目录,请使用通配符(*)。

例如:

gsutil -q stat gs://some-bucket/some-subdir/*; echo $?

在你的情况下:

gsutil -q stat gs://main-bucket/sub-directory-bucket/*; echo $?

结果0表示存在; 1表示不存在


1
投票

还有gsutil lshttps://cloud.google.com/storage/docs/gsutil/commands/ls

EG

gsutil ls gs://my-bucket/foo.txt

输出是相同的文件路径或“CommandException: One or more URLs matched no objects.

© www.soinside.com 2019 - 2024. All rights reserved.