GoogleCloudPlatform / GoogleCloudPlatform/gsutil

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

Open
#1,746 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
918
Forks
335
PR merge metrics
No merged PRs in 30d

Description

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:

```bash
# 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`

Contributor guide

Open the contributing guide

Research direction

Start by examining the existing `gsutil ls` behavior and the `gsutil stat` output used in the issue's workaround. Define how timestamp sorting should be requested and ordered, then verify that `gsutil ls` can list files and directories sorted by their timestamps without the external shell loop.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.