Skip to content

Instantly share code, notes, and snippets.

@bahamas10
Created November 10, 2025 18:40
Show Gist options
  • Select an option

  • Save bahamas10/43c0b27f69d867e6f7c0a2dbcf92c060 to your computer and use it in GitHub Desktop.

Select an option

Save bahamas10/43c0b27f69d867e6f7c0a2dbcf92c060 to your computer and use it in GitHub Desktop.
update album directory mtime to match oldest file in the directory
#!/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