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

Chris Stryczynski picture Chris Stryczynski · Aug 18, 2017 · Viewed 8.7k times · Source

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.

Answer

night-gold picture night-gold · Jan 16, 2019

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.