gsutil / gcloud storage file listing sorted date descending?

Dhiraj Gupta picture Dhiraj Gupta · Mar 1, 2018 · Viewed 11.8k times · Source

Is there no way to get a file listing out from a Google Cloud Storage bucket that is sorted by date descending? This is very frustrating. I need to check the status of files that are uploaded and the bucket has thousands of objects.

gsutil ls does not have the standard linux -t option.

Google cloud console also lists it but does not offer sorting options.

Answer

torno picture torno · Aug 6, 2018

I use this as a workaround:

gsutil ls -l gs://[bucket-name]/ | sort -k 2

This outputs full listing including date as the second field, sort -k 2 then sorts by this field.