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?
6 Answers
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.
-
1I 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.– MichaelDec 4, 2019 at 17:31
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
-
1Set 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
Oct 7, 2020 at 10:36 -
1Unlike
exiv2
, this also worked on 3g2 and mkv files (video containers) for me.– JohannJan 14, 2021 at 16:28
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.
-
2
-
5jhead 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.– MichaelDec 4, 2019 at 17:48
-
1I 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! Jun 30, 2020 at 10:28 -
Worked like a charm! I have been looking for this for a long time Jul 26, 2022 at 3:56
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
-
can you describe what this script is doing? In particular the args for
exiftool
Oct 15, 2018 at 1:43
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.
ExifDate2FS tool will do this.
pip install exifdate2fs
exifdate2fs /opt/folder_with_your_photos/