gsutil / gcloud storage file listing sorted date descending?

19,604

Solution 1

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.

Solution 2

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.

Share:
19,604
Dhiraj Gupta
Author by

Dhiraj Gupta

Seasoned and passionate software engineer, entrepreneur with a never-give-up attitude. Constantly learning, developing new ideas for many years of professional experience Patient, relentless - will unceasingly work towards achieving set goals Excels in starting up products from idea stage and taking them to fruition Multi-functional - experienced in diverse technological and business areas Twitter | GitHub | LinkedIn

Updated on June 13, 2022

Comments

  • Dhiraj Gupta
    Dhiraj Gupta about 2 years

    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.