Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gsutil / gcloud storage file listing sorted date descending?

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.

like image 539
Dhiraj Gupta Avatar asked Mar 01 '18 08:03

Dhiraj Gupta


2 Answers

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.

like image 56
torno Avatar answered Nov 15 '22 20:11

torno


The only ordering supported by GCS is lexicographic.

As a workaround, if it's possible for you to name your objects with a datestamp, that would give you a way to list objects by date.

like image 5
Mike Schwartz Avatar answered Nov 15 '22 19:11

Mike Schwartz