Is there a way to remove files from GoogleCloudStorage, using the CLI by their creation date?
For example: I would like to remove all files in a specific path, which their creation date is lower than 2016-12-01
Is there a way to remove files from GoogleCloudStorage, using the CLI by their creation date?
For example: I would like to remove all files in a specific path, which their creation date is lower than 2016-12-01
There's no built-in way in the CLI to delete by date. There are a couple ways to accomplish something like this. One possibility is to use an object naming scheme that prefixes object names by their creation date. Then it is easy to remove them with wildcards, for example:
gsutil -m rm gs://your-bucket/2016-12-01/*
Another approach would be to write a short parser for
gsutil ls -L gs://your-bucket
that filters object names by their creation date, then callgsutil -m rm -I
with the resulting object names.If you just want to automatically delete objects older than a certain age, then there is a much easier way than using the CLI: you can configure an Object Lifecycle Management policy on your bucket.