55

When uploading to an ftp site, the original file create date seems to be lost, and I get the upload date instead. However, the Exif data in the file is correct. Is there a tool to batch change the created date from the Exif date?

Volker Siegel
  • 17,283
Finn Ove
  • 551
  • 3
    Please consider accepting the answer that you find the most helpful. This way, other people who search for this question will see it marked as "answered". It's also a way to reward a person who have spent their time helping you. – Dmitry Grigoryev Sep 17 '15 at 08:11

6 Answers6

47

The EXIF handling tool exiv2 has a builtin option for this:

exiv2 -T rename image.jpg

sets the time of last file modification, mtime, to the date stored in the EXIF metadata.

You asked for using the create time - but that is not used in Unix-like systems, and there are good reasons for that.

I'm pretty sure the time you call create time is actually mtime, no problem there.

From man exiv2:

NAME
  exiv2 - Image metadata manipulation tool

SYNOPSIS exiv2 [options] [action] file ...

DESCRIPTION exiv2 is a program to read and write Exif, IPTC and XMP image metadata and image com‐ ments. The following image formats are supported:

[ ... ]

mv | rename Rename files and/or set file timestamps according to the Exif create time‐ stamp. Uses the value of tag Exif.Photo.DateTimeOriginal or, if not present, Exif.Image.DateTime to determine the timestamp. The filename for‐ mat can be set with -r fmt, timestamp options are -t and -T.

[ ... ]

-T Only set the file timestamp according to the Exif create timestamp, do not rename the file (overrides -k). This option is only used with the 'rename' action. Note: On Windows you may have to set the TZ environment variable for this option to work correctly.

See option -t to do the opposite.

Pablo A
  • 2,712
Volker Siegel
  • 17,283
  • 1
    I would interpret "opposite" to mean to set the EXIF timestamp from the file timestamp, but this is not what -t does. In fact, it seems to actually do a superset of what -T does. – Michael Dec 04 '19 at 17:31
17

Assuming, as mentioned by 'Volker Siegel', that you probably mean mtime, I would simple use exiftools builtin function..

like:

 $ exiftool "-DateTimeOriginal>FileModifyDate" test.jpg

this will take the "exif field "DateTimeOriginal" information and use it to set the filesystems modified date/time info of the file "test.jpg".

Example:

$ ls -la test.jpg
-rw-r-----@ 1 user  18329968  2432451 14 Out 17:57 test.jpg

$ exiftool -DateTimeOriginal test.jpg Date/Time Original : 2015:10:09 13:29:58

$ exiftool "-DateTimeOriginal>FileModifyDate" test.jpg 1 image files updated

$ ls -la test.jpg -rw-r-----@ 1 user 18329968 2432451 9 Out 13:29 test.jpg

6ugr3
  • 271
  • 1
    Set the timezone environment variable in case the EXIF-field contains a time in a different timezone. For example: TZ=Asia/Shanghai exiftool "-DateTimeOriginal>FileModifyDate" test.jpg – Peter Nowee Oct 07 '20 at 10:36
  • 1
    Unlike exiv2, this also worked on 3g2 and mkv files (video containers) for me. – Johann Jan 14 '21 at 16:28
12

It can also be made using jhead command:

$ jhead -ft file.jpg

From man page:

-ft Sets the file's system time stamp to what is stored in the Exif header.

-dsft Sets the Exif timestamp to the file's timestamp. Requires an Exif header to pre-exist. Use -mkexif option to create one if needed.

Pablo A
  • 2,712
SkyRaT
  • 321
  • 2
  • 3
  • 2
    For Jhead 3.0 the option is -dsft. -ft does the opposite. – Tesquin Crydd Nov 04 '16 at 12:28
  • 5
    jhead seems to be the only EXIF tool which doesn't muck with the EXIF header - exiftool and exiv2 actually increase the size of the file and move headers around, which is totally unacceptable to me. – Michael Dec 04 '19 at 17:48
  • 1
    I disagree that jhead 3 requires opposite arguments. The man page confirms the answer and my testing does as well. I am currently running find /my/picture/path -type f -iname \*pg -print0 | xargs -0 -n 1 jhead -exonly -ft which seems to be working. -exonly seems to be necessary to not set the date on every file without an EXIF header (many thumbnails) to 2098-01-18. An odd default behavior! – Bill McGonigle Jun 30 '20 at 10:28
  • Worked like a charm! I have been looking for this for a long time – Sriram Kannan Jul 26 '22 at 03:56
9

If you install the exiftool from CPAN you can run the following script, assuming that all your files are in a directory called "all"

#!/bin/sh
for i in all/*; do
    SPEC=`exiftool -t -s -d "%Y-%m-%d %H:%M:%S" -CreateDate "$i"`
    read X DATE <<<${SPEC}
    echo "$i:$DATE"
    touch -d "$DATE" "$i"
done
Joel Taylor
  • 923
  • 6
  • 13
5

ExifTool can read and manipulate most EXIF information, including extracting the Date/Time Original or Create Data EXIF tags. You can use this information to rename the files or change their timestamps. For example:

find -name '*.jpg' | while read PIC; do
    DATE=$(exiftool -p '$DateTimeOriginal' $PIC |
    sed 's/[: ]//g')
    touch -t $(echo $DATE | sed 's/\(..$\)/\.\1/') $PIC
done

This will find all JPG files in the current directory and update the timestamps.

If you want to also give those files a name based on that date (this tends to come in handy) then also add mv -i $PIC $(dirname $PIC)/$DATE.jpg before the done line.

krowe
  • 746
1

ExifDate2FS tool will do this.

pip install exifdate2fs
exifdate2fs /opt/folder_with_your_photos/
Eugene V
  • 11
  • 1