Change file created date from JPEG EXIF metadata
Solution 1
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.
Solution 2
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
Solution 3
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.
Solution 4
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
Solution 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.
Related videos on Youtube
Volker Siegel
I like to answer older questions, if I have an additional perspective to the question to give. Adding an additional answer even if there are valid answers can still add value to the collection of answers and questions we are building here. (A late answer does, by it's nature, get not much attention, so it leads to exceptionally low reputation per answer. But hey, that's life, right?) And I feel it's the important thing here: We're answering professional questions in a professional way, and often do that quickly. That's of great value for the general public. But the real thing of value, that is of value hard to describe in simple terms, is the body of text, the whole collection that we are creating here together. All participants here, whether he or she cares more about asking, answering or collecting questions and answers. This applies to all StackExchange sites and topics in the same way. In some sites and topics, I like to add questions that have only the purpose of growing the collection, often more academic than practical, and of general interest while not too trivial. I'm here because I want to take part in the creation of this exceptional body of well structured knowledge.
Updated on September 18, 2022Comments
-
Volker Siegel over 1 year
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?
-
Admin over 8 yearsPlease 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.
-
-
Tesquin Crydd over 7 yearsFor Jhead 3.0 the option is
-dsft
.-ft
does the opposite. -
user5359531 over 5 yearscan you describe what this script is doing? In particular the args for
exiftool
-
Michael over 4 yearsI 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 over 4 yearsjhead 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.
-
Bill McGonigle almost 4 yearsI 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! -
Peter Nowee over 3 yearsSet 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
-
Johann over 3 yearsUnlike
exiv2
, this also worked on 3g2 and mkv files (video containers) for me.