gsutil returning "no matches found"
Asked Answered
P

3

42

I'm trying using gsutil to remove the contents of a Cloud Storage bucket (but not the bucket itself). According to the documentation, the command should be:

gsutil rm gs://bucket/**

However, whenever I run that (with my bucket name substituted of course), I get the following response:

zsh: no matches found: gs://my-bucket/**

I've checked permissions, and I have owner permissions. Additionally, if I specify a file, which is in the bucket, directly, it is successfully deleted.

Other information which may matter:

  • My bucket name has a "-" in it (similar to "my-bucket")
  • It is the bucket that Cloud Storage saves my usage logs to

How do I go about deleting the contents of a bucket?

Photima answered 22/8, 2016 at 8:57 Comment(0)
A
128

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/**'

Note that you need to use single (not double) quotes to prevent zsh wildcard handling.

Aloft answered 22/8, 2016 at 15:12 Comment(0)
W
0

If you have variables to replace, you can also just escape the wildcard character

Examples with copy (with interesting flags) and rm

GCP_PROJECT_NAME=your-project-name

gsutil -m cp -r gs://${GCP_PROJECT_NAME}.appspot.com/assets/\* src/local-assets/
gsutil rm gs://${GCP_PROJECT_NAME}.appspot.com/\*\*
Warmongering answered 4/1, 2023 at 23:57 Comment(0)
B
-5
gsutil rm  gs://bucketName/doc.txt

And for remove entire bucket including all objects

gsutil rm -r gs://bucketname
Befool answered 28/4, 2018 at 7:35 Comment(1)
Use the gsutil rm command with the -r flag to delete the bucket and anything inside of it: gsutil rm -r gs://my-awesome-bucketBefool

© 2022 - 2024 — McMap. All rights reserved.