google-cloud-platformgoogle-cloud-storagegsutil

How to retrieve the most recent file in cloud storage bucket?


Is this something that can be done with gsutil?

https://cloud.google.com/storage/docs/gsutil/commands/ls does not seem to mention any sorting functionality - only filtering by a date - which wouldn't work for my use case.


Solution

  • Hello this still doesn't seems to exists, but there is a solution in this post: enter link description here

    The command used is this one:

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

    As it allow you to filter by date you can get the most recent result in the bucket and recuperating the last line using another pipe if you need.