Last active
February 3, 2026 20:26
-
-
Save dacr/d9961acb0fb82184301857bc9e8860ea to your computer and use it in GitHub Desktop.
Fix photo exif camera shoot date time for all files within the current directory / published by https://github.com/dacr/code-examples-manager #16b49052-c908-4e54-ad2c-0c6d09703b66/c8d48a66e79c392d667c35f83b65976722a3ad4d
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
| ## summary : Fix photo exif camera shoot date time for all files within the current directory | |
| ## keywords : bash, exiftool, timestamp, | |
| ## publish : gist | |
| ## authors : David Crosson | |
| ## license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| ## id : 16b49052-c908-4e54-ad2c-0c6d09703b66 | |
| ## created-on : 2025-08-06T07:07:56+02:00 | |
| ## managed-by : https://github.com/dacr/code-examples-manager | |
| ## run-with : sh $file | |
| # Validate and get base timestamp from first argument | |
| if [ $# -eq 0 ]; then | |
| echo "Error: Base timestamp argument is required" | |
| echo " such as '2024:01:01 20:10:30'" | |
| exit 1 | |
| fi | |
| BASE_TS="$1" | |
| # Enable case-insensitive globbing | |
| shopt -s nocaseglob | |
| COUNTER=0 | |
| for INPUT in *.{jpg,png,JPG,PNG,jpeg,JPEG}; do | |
| [ -e "$INPUT" ] || continue | |
| TS=$(exiftool -s -s -s -DateTimeOriginal "$INPUT") | |
| #if [[ "$TS" == "0000:00:00 00:00:00" || "$TS" == "" ]] ; then | |
| COUNTER=$((COUNTER + 1)) | |
| SECS=$(date +%s --date="$BASE_TS") | |
| NEW_TIME=$(date '+%Y:%m:%d %H:%M:%S' --date="@$((SECS + COUNTER))" ) | |
| echo "$INPUT: $TS -> $NEW_TIME" | |
| exiftool -overwrite_original "-DateTimeOriginal=$NEW_TIME" "$INPUT" | |
| #fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment