photo exif timestamp / filesystem mtime

photo exif timestamp / filesystem mtime

  • Written by
    Walter Doekes
  • Published on

Sometimes, after a stray copy operation, your filesystem times may reflect the time the files were copied instead of when the file was actually last altered.

For example this image folder here:

$ ls -l phone2013
total 320856
-rw-rw-r-- 1 walter walter 1524591 nov 17 21:52 2012-10-28 08.54.58.jpg
-rw-rw-r-- 1 walter walter 1534840 nov 17 21:52 2012-10-28 08.55.04.jpg
-rw-rw-r-- 1 walter walter 1635908 nov 17 21:52 2012-10-28 08.55.09.jpg
...
-rw-rw-r-- 1 walter walter 1600504 nov 17 21:52 2013-10-22 11.54.25.jpg
-rw-rw-r-- 1 walter walter 1478624 nov 17 21:52 2013-10-22 12.04.57.jpg

This time, the filename happens to hold the date (Samsung phone), but many other times, the filenames will look like IMG_7897.JPG or similar.

Can we restore the filesystem modification (creation) times from the timestamp which is contained in the JPEG?

Yes we can, using exiftran(1) and a small littly utility I hacked up.

Let’s see how that works:

$ exifdate2fs.sh -A
./phone2013/2013-10-21 10.40.03.jpg: 201310211040.02
./phone2013/2012-10-28 08.55.29.jpg: 201210280855.28
./phone2013/2013-03-09 15.07.10.jpg: 201303091507.09
...
./phone2013/2013-03-09 14.03.03.jpg: 201303091403.01
./phone2013/2013-10-21 10.41.39.jpg: 201310211041.38
./phone2013/: 201310221204.56

Right on. That exifdate2fs -A iterated over all JPG files in . and below and fixed the times. And now things look like they should, including the directory itself.

$ ls -l
total 44
drwxrwxr-x 2 walter walter 40960 okt 22  2013 phone2013

$ ls -l phone2013/
total 320856
-rw-rw-r-- 1 walter walter 1524591 okt 28  2012 2012-10-28 08.54.58.jpg
-rw-rw-r-- 1 walter walter 1534840 okt 28  2012 2012-10-28 08.55.04.jpg
-rw-rw-r-- 1 walter walter 1635908 okt 28  2012 2012-10-28 08.55.09.jpg
...
-rw-rw-r-- 1 walter walter 1600504 okt 22  2013 2013-10-22 11.54.25.jpg
-rw-rw-r-- 1 walter walter 1478624 okt 22  2013 2013-10-22 12.04.57.jpg

Get it here while it’s hot: exifdate2fs.sh (view)


Back to overview Newer post: django / makemessages / slow Older post: python / ctypes / socket / datagram