skhurams
skhurams

Reputation: 2145

How to delete object, filter by extension in Google Cloud Storage

Whats the best way to delete google cloud storage objects filtered by extensions? I have a bucket that contains folders with millions of .html and .jpg extension files and I'd like to automatically delete only html files older than 2 years. I want to apply a rule using Object Lifecycle Management.

I have read the article1 and article2 which shows to apply rule for all objects but I only want to delete html files.

Upvotes: 0

Views: 802

Answers (1)

phteven
phteven

Reputation: 463

I don't believe this can be done with Object Lifecycle Management. It does not have a condition to specify file extensions. I would try to craft a list of files to remove by creation date with gsutil stat and wildcards and then remove those files with a piped gsutil rm. Something like this should work:

cat filestoremove.txt | gsutil -m rm -I

Per the gsutil rm doc page the txt has to contain object URLs for this to work. One per line.

Upvotes: 1

Related Questions