39

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?

Arnon Rotem-Gal-Oz
  • 25,469
  • 3
  • 45
  • 68
JohnGB
  • 1,906
  • 2
  • 20
  • 31

3 Answers3

122

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.

Mike Schwartz
  • 11,511
  • 1
  • 33
  • 36
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/\*\*
Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164
-4
gsutil rm  gs://bucketName/doc.txt

And for remove entire bucket including all objects

gsutil rm -r gs://bucketname
rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
sumer raj
  • 1
  • 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-bucket – sumer raj Apr 28 '18 at 20:15