首页 > 解决方案 > 连接两个 GSUtil 命令

问题描述

我想在一行中执行两个 gsutil 命令,我该如何实现。例如:

gsutil ls gs://projectname/bucketname/folder1/folder2/filename.png | \
 cp gs://projectname/bucketname/folder3/folder4/

从特定存储桶中查找/列出文件并将同一文件复制到存储桶文件夹。在上面的命令中,我使用的是 ls (列表)和 cp (复制)命令,但这没有按预期工作。

类似于下面的 shell 脚本或 linux 命令,我们使用 exec 并继续执行下一个命令。

find -type f -path '*schedule*/*' -name "*.png" -exec cp -n {} /tmp/MusicFiles \;

非常感谢您的早期回复。提前致谢..!

标签: concatenationgsutil

解决方案


Oneliner:来自gsutil help cp

  -I             Causes gsutil to read the list of files or objects to copy from
                 stdin. This allows you to run a program that generates the list
                 of files to upload/download.

所以,some_program | gsutil -m cp -I gs://my-bucket

一些程序可以在哪里gsutil ls ...

此外,

gsutil 接受通配符,因此该命令将是这样的。

gsutul cp gs:/bucket-name/*schedule*/*/*.png gs://bucketname/folder3/folder4/

请注意,递归通配符可以使用单星*和双星**


推荐阅读