2.5 KiB
2.5 KiB
+++ date = '2026-03-10T18:37:42+01:00' draft = false title = 'Modify Image Timestamp' type='post' tags = ['Linux', 'Photography'] +++ Some cameras don't automatically update their internal clock. This leads to images with "wrong" timestamps. Modifying the file metadata as well as the Exif metadata can fix this problem.
Modifying the file metadata
touch -m -d "<date>" "<file_name>"
-monly modify the modification date-d "<date>"use<date>instead of the current date<file_name>name of the file to be modified
Example Script for adding an offset
The following command adds 20 years and 7 months while subtracting 6 days.
#!/bin/bash
original_mtime=$(stat -c %y "<file_name>")
new_mtime=$(date -d "$original_mtime +20 years +7 months -6 days" '+%Y-%m-%d %H:%M:%S')
touch -m -d "$new_mtime" "<file_name>"
stat -c %y "<file_name>"reads the current modification timestamp from the filedate -d ...calculates the new date
Modifying the Exif metadata
exiftool -P -overwrite_original "-allDates=<date>" "<file_name>"
exiftoolFOSS tool for viewing and modifying Exif data (source)-Pto not overwrite the file modification time (file metadata)allDates=...modifies the exif metadata dates- can be used with operators (i.e.
+=,-=) for offsets
- can be used with operators (i.e.
Example Script for adding an offset
The following command adds 20 years and 7 months while subtracting 6 days.
#!/bin/bash
exiftool -P -overwrite_original "-allDates+=20:7:0 0:0:0" "<file_name>"
exiftool -P -overwrite_original "-allDates-=0:0:6 0:0:0" "<file_name>"
Example Script for Combined Modification
This script modifies all .JPG files in a given directory by adding 20 years and 7 months while subtracting 6 days.
#!/bin/bash
find "<dir_name>" -type f -iname "*.JPG" -print0 | while IFS= read -r -d '' file; do
echo "Processing $file"
#update meta data
original_mtime=$(stat -c %y "$file")
new_mtime=$(date -d "$original_mtime +20 years +7 months -6 days" '+%Y-%m-%d %H:%M:%S')
touch -m -d "$new_mtime" "$file"
#update exif data
exiftool -P -overwrite_original "-allDates+=20:7:0 0:0:0" "$file"
exiftool -P -overwrite_original "-allDates-=0:0:6 0:0:0" "$file"
done
echo "DONE!"
<dir_name>name of the directory to be modified