如何使用通配符gsutil删除特定子目录?

huangapple go评论47阅读模式
英文:

How to delete specific sub directory with wildcard gsutil?

问题

这个问题的启发,我正在尝试使用gsutil命令中的通配符来删除存储桶中的特定文件夹,例如:

gsutil rm -r gs://bucket-name/path/to/**/content

或者

gsutil rm -r gs://bucket-name/path/to/*/content

这会引发以下错误:

zsh: no matches found: gs://bucket-name/path/to/**/content
zsh: no matches found: gs://bucket-name/path/to/*/content

其中的 *** 用来替代ID(成千上万的记录),每个ID下都有2个目录:contentcontent2,我只想删除content目录。

提前感谢您的帮助。

英文:

Inspired by this question i am trying to delete specific folders from my bucket using wildcard in a gsutil command such as :

gsutil rm -r gs://bucket-name/path/to/**/content 

or

gsutil rm -r gs://bucket-name/path/to/*/content 

This is throwing the error :

zsh: no matches found: gs://bucket-name/path/to/**/content
zsh: no matches found: gs://bucket-name/path/to/*/content

Where the * or ** is replacing IDs (thousands of records) and under each there are 2 directories : content, content2 and i only want to remove the content directory

Thanks in advance

答案1

得分: 2

按照Mike Schwartz的这个回答,在使用通配符时,您必须使用单引号或双引号。

zsh在gsutil看到通配符之前尝试展开它(并抱怨您没有本地文件与该通配符匹配)。请尝试以下方式,以防止zsh这样做:

gsutil rm 'gs://bucket/**'
英文:

As per this answer by @Mike Schwartz, You have to use single or double quotes while using wildcards.

> zsh is attempting to expand the wildcard before gsutil sees it (and is complaining that you have no local files matching that wildcard). Please try this, to prevent zsh from doing so:
>
>
>gsutil rm 'gs://bucket/**'
>

huangapple
  • 本文由 发表于 2023年2月19日 01:55:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75495290.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定