Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nick-youngblut opened this issue Sep 19, 2023 · 1 comment
Open

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

nick-youngblut opened this issue Sep 19, 2023 · 1 comment

Comments

@nick-youngblut
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants