Created
November 10, 2025 18:40
-
-
Save bahamas10/43c0b27f69d867e6f7c0a2dbcf92c060 to your computer and use it in GitHub Desktop.
update album directory mtime to match oldest file in the directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| cd /goliath/entertainment/Music/DavesMusic/ || exit 1 | |
| # loop each album | |
| for f in */*/; do | |
| echo "album: $f" | |
| # get the mtime of every song and keep the oldest | |
| oldest=$(stat --format '%Y %n' "$f"* | sort -n | head -1) | |
| if [[ -z $oldest ]]; then | |
| echo "failed to find timestamp" >&2 | |
| continue | |
| fi | |
| # we don't keep the timestamp - we just keep the name of the file with | |
| # the oldest timestamp to use as a reference to the touch command | |
| read -r ts ref <<< "$oldest" | |
| echo "mtime -> $ts (ref file: $ref)" | |
| # touch -r "$ref" "$f" | |
| echo | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment