Skip to content

Instantly share code, notes, and snippets.

@jac18281828
Created October 17, 2025 01:36
Show Gist options
  • Save jac18281828/a56eb619cb90e84186abe70aee30bae2 to your computer and use it in GitHub Desktop.
Save jac18281828/a56eb619cb90e84186abe70aee30bae2 to your computer and use it in GitHub Desktop.
set mtime to creation time for photos
#!/bin/bash
# set_mtime_to_creation.sh
# Sets each file's modification time to its creation time (macOS / BSD)
shopt -s nullglob
for file in *; do
# Skip directories
if [ -d "$file" ]; then
continue
fi
# Get creation time in epoch seconds
birth=$(stat -f "%B" "$file" 2>/dev/null)
# Skip if stat fails or returns 0
if [ -z "$birth" ] || [ "$birth" -eq 0 ]; then
echo "Skipping '$file' (no creation time)"
continue
fi
# Convert to touch timestamp format
touch_time=$(date -r "$birth" +"%Y%m%d%H%M.%S")
# Apply creation time to modification time
touch -mt "$touch_time" "$file"
echo "Updated '$file' → mtime set to creation time ($touch_time)"
done
echo "✅ Done: All applicable files updated."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment