连接两个 GSUtil 命令

问题描述 投票:0回答:2

我想在一行中执行两个 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 \;

非常感谢您的早期回复。预先感谢..!

concatenation gsutil
2个回答
0
投票

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/

请注意,可以对递归通配符使用单星

*
和双星
**


0
投票

Juancki 提供的答案解决了 OP 处理文件输入列表的目标,如果您到达这里(就像我一样),请继续阅读 - 寻找一种操作内容的方法(即修剪输入文件的最后几行)。

不要使用 Juancki 响应中的“-I”,而是使用“-”,表示从标准输入中提取。

例如,下面的命令将指定的字节范围从 customer.rpt 复制到 customer_clean.rpt

$ gsutil cat -r 0-338164333 gs://poc/customer.rpt | gsutil cp - gs://poc/customer_clean.rpt

完整示例@https://stackoverflow.com/a/78719448/25045468

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