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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With