Update Modification Time According to EXIF Data


Question:

Find photo/video and update modification time (mtime) of the photo/video according to EXIF data.

Answer:

Install exiftool:

$ sudo apt-get install libimage-exiftool-perl

Find photo/video. The -i in -iregex means case insensitive.

$ find . -type f -iregex '.*\.\(jpg\|gif\|png\|jpeg\|mov\|mp4\|heic\)$'

Update modification time according to EXIF data.

$ find . -type f -iregex '.*\.\(jpg\|gif\|png\|jpeg\|mov\|mp4\|heic\)$' | xargs -I {} exiftool "-DateTimeOriginal>FileModifyDate" {}

Update modification time according to creation date (for iPhone MOV file). [5]

$ find . -type f -iregex '.*\.\(jpg\|gif\|png\|jpeg\|mov\|mp4\|heic\)$' | xargs -I {} exiftool "-CreationDate>FileModifyDate" {}

Instead of exiftool, you can also use jhead to update mtime.

$ sudo apt-get install jhead

Use jhead along with find command:

$ find . -type f -iregex '.*\.\(jpg\|gif\|png\|jpeg\|mov\|mp4\|heic\)$' -exec jhead -ft {} +

References:

[1]images - Change file created date from JPEG EXIF metadata - Unix & Linux Stack Exchange
[2]regular expression - How to use find command to search for multiple extensions - Unix & Linux Stack Exchange
[3]Is there a free program to (batch) change photo file's date to match EXIF? - Photography Stack Exchange
[4]timestamp - How can I change the date modified/created of a file? - Ask Ubuntu
[5]Getting metadata for MOV video - Stack Overflow