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>"
  • -m only 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 file
  • date -d ... calculates the new date

Modifying the Exif metadata

exiftool -P -overwrite_original "-allDates=<date>" "<file_name>"
  • exiftool FOSS tool for viewing and modifying Exif data (source)
  • -P to not overwrite the file modification time (file metadata)
  • allDates=... modifies the exif metadata dates
    • can be used with operators (i.e. +=, -=) for offsets

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