Created
December 15, 2025 17:29
-
-
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/3ca1fff89f66b14630eecdc790e7b2b92ad278bc
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 NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
| ## 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