Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to find all files/objects in a Google Cloud Storage Bucket larger than a certain size?

I'm trying to use the du command but I'm not sure how to filter by file size. Trying to do this to delete big files that I simply don't need and are costing me money.

like image 984
James Hanson Avatar asked Oct 19 '25 10:10

James Hanson


1 Answers

With python you can get a list of all blobs in your bucket and loop through that list to get those with a large size:

from google.cloud import storage

storage_client = storage.Client()

blobs_list = storage_client.list_blobs(bucket_or_name='name_of_your_bucket')

large_files = []
for blob in blobs_list:
    if blob.size > 1_000_000:  # size is in bytes
        large_files.append(blob.id)
like image 176
Sander van den Oord Avatar answered Oct 22 '25 03:10

Sander van den Oord



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!