google-cloud-platformgoogle-cloud-storage

Deleting a large folder from Google Cloud Storage


I have a folder in a Google Cloud Storage bucket, which has millions of files that I need to remove.

What is an efficient way to delete this large folder of files, without having to delete the entire bucket?

I've tried using the gsutil rm command, but it seems like it will take a long time to finish deleting all files.

Furthermore, I also read about Object Lifecycle Management policies, but I read that they apply to the entire bucket, as opposed to any specific folder.

Thanks for your help! :)


Solution

  • gsutil rm will be fastest. Your only alternative is to write code to list and delete each one, which is what gsutil is going to do for you.