GoogleCloudPlatform / gsutil

A command line tool for interacting with cloud storage services.
Apache License 2.0
873 stars 333 forks source link

feature request: `gsutil ls` => sort by timestamp #1746

Open nick-youngblut opened 1 year ago

nick-youngblut commented 1 year ago

As far as I can tell, gsutil ls (v5.25) does not allow for sorting by file/directory timestamps. I could use something like the following to accomplish this:

# List all files in a GCS bucket
files=$(gsutil ls gs://your-bucket-name/*)

# Initialize an empty associative array to hold file creation times
declare -A file_dates

# Loop through each file to get its creation date
for file in $files; do
  creation_date=$(gsutil stat $file | grep "Creation time:" | awk -F: '{print $2 $3 $4}')
  file_dates["$file"]=$creation_date
done

# Sort files by creation date and print
for file in $(echo "${!file_dates[@]}" | tr ' ' '\n' | sort -k3); do
  echo "$file - ${file_dates[$file]}"
done

...but it would be great to have this feature built directly into gsutil

RahulDubey391 commented 10 months ago

Hi @nick-youngblut , I would like to work on this issue. Can you please assign it to me?