28

I have hundred files under a folder in Google Cloud Storage. But, the UI doesn't give me a way to select all files at once.

How can I select all files and delete them at once ?

3 Answers 3

52

The easiest way would be to use the command-line utility, gsutil. This command will delete them all:

gsutil -m rm gs://BUCKET_NAME/**

If you want to delete the bucket as well, you could do this instead:

gsutil -m rm -R gs://BUCKET_NAME
2
  • I'm presuming this syntax has changed, I just get an error no matches found: gs://BUCKET_NAME/** when running gsutil -m rm gs://BUCKET_NAME/**
    – Liam
    Commented Oct 28, 2022 at 19:05
  • 2
    Ah, the issue was that I was running this command using zsh which expands the **, see this answer
    – Liam
    Commented Oct 28, 2022 at 19:09
12

I came across this problem myself a month or so ago, I had > 800,000 files to delete from a bucket.

After a lot of searching around, and an email to the GCS team, I found that the best way was to get GCS to delete the files for me by setting an Object Lifecycle Management policy to expire all of the files.

The only downside is that this method is not instant, it can take up to 24 hours until the files expire and are deleted, but once setup it will happen automatically.

1
  • @Brandon Yarbrough, though I have the same query. I wanted to know how to delete objects under a folder within a bucket and not drop the folder or bucket?. Bucket:'Itsanewone' folder:'DropMe'. I want to clear DropMe folder without droping 'DropMe'. I tried the following code gsutil rm gs://itsanewone/DropMe/** Commented Jul 8, 2015 at 3:59
-6

simple command Type command in cloud console terminal

rm -rf [foldername]

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