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?

3 Answers 3

128
Answer recommended by Google Cloud Collective

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.

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/\*\*
-5
gsutil rm  gs://bucketName/doc.txt

And for remove entire bucket including all objects

gsutil rm -r gs://bucketname
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
    Commented Apr 28, 2018 at 20:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.