Discussion:
Using exif and touch
(too old to reply)
Michael Hufschmidt
2011-08-08 14:22:05 UTC
Permalink
Hi Folks,

there exists a nice command line utility "exif" which can read (and set)
exif data from .jpg pictures. On the oter hand I can set the file
creation date with the command "touch". Now I want to set all file dates
of pictures in the current directory to the exif date and time. How
could I do that in a shell script?

Thanks in advance for any suggestions - Michael
Lew Pitcher
2011-08-08 14:32:06 UTC
Permalink
Post by Michael Hufschmidt
Hi Folks,
there exists a nice command line utility "exif" which can read (and set)
exif data from .jpg pictures.
Note that this "exif" commandline utility does not exist on many systems.
Only those familiar with the "exif" tool on /your/ platform (whatever that
is) can properly assist you with the use of that tool.
Post by Michael Hufschmidt
On the oter hand I can set the file creation date with the
command "touch".
Actually, no, you can't "set the file creation date with the
command 'touch'" Unix files /don't have/ a "file creation date"

You /can/ set the "last modified" date, or the "last access" date, or
the "last inode change" date with touch(1), though.
Post by Michael Hufschmidt
Now I want to set all file dates of pictures in the current directory to
the exif date and time. How could I do that in a shell script?
You'll need a utility that reads exif data from picture files, and sets the
file date(s) accordingly. Perhaps the "exif" utility you talked about
earlier can do that; I don't know, as that "exif" utility isn't standard on
Unix-ish systems.

FWIW, the jhead(1) utility (from
http://www.sentex.net/~mwandel/jhead/) /can/ set file inode dates based on
Exif date data (see the -ft option).
Post by Michael Hufschmidt
Thanks in advance for any suggestions - Michael
HTH
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------
Lew Pitcher
2011-08-08 14:53:17 UTC
Permalink
Post by Michael Hufschmidt
Hi Folks,
there exists a nice command line utility "exif" which can read (and set)
exif data from .jpg pictures.
[snip]
Post by Michael Hufschmidt
Now I want to set all file dates of pictures in the current directory to
the exif date and time. How could I do that in a shell script?
For what it's worth, assuming that this "exif" commandline tool reads /and
displays/ the exif date, you could write a shell script that

for each file that matches ./*.[Jj][P][G]
run the exif tool to extract the photo date from the matching file
pipe the output into a script that isolates the date and converts it to a
common format
use that common format date as the parameter to touch to set the
atime/mtime/ctime values for the matching file

HTH
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------
Lew Pitcher
2011-08-08 18:21:29 UTC
Permalink
Post by Lew Pitcher
Post by Michael Hufschmidt
Hi Folks,
[snip]
Post by Lew Pitcher
Post by Michael Hufschmidt
Now I want to set all file dates of pictures in the current directory to
the exif date and time. How could I do that in a shell script?
[snip]
Post by Lew Pitcher
FWIW, the jhead(1) utility (from
http://www.sentex.net/~mwandel/jhead/) /can/ set file inode dates based on
Exif date data (see the -ft option).
For example
jhead -ft ./*.[Jj][Pp][Gg]
would do what you are looking for
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------
John DuBois
2011-08-08 17:03:20 UTC
Permalink
Post by Michael Hufschmidt
Hi Folks,
there exists a nice command line utility "exif" which can read (and set)
exif data from .jpg pictures. On the oter hand I can set the file
creation date with the command "touch". Now I want to set all file dates
of pictures in the current directory to the exif date and time. How
could I do that in a shell script?
Here's a simple example. It uses exiflist but should translate
easily to other EXIF listing utilities.

ftp://ftp.armory.com/pub/scripts/exiftouch

John
--
John DuBois ***@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Janis Papanagnou
2011-08-08 18:10:16 UTC
Permalink
Post by Michael Hufschmidt
Hi Folks,
there exists a nice command line utility "exif" which can read (and set) exif
data from .jpg pictures. On the oter hand I can set the file creation date
with the command "touch". Now I want to set all file dates of pictures in the
current directory to the exif date and time. How could I do that in a shell
script?
Thanks in advance for any suggestions - Michael
Here's something that I once wrote and found in my ~/bin directory...


for f in "$@"
do
# exiftool data format:
# Create Date : 2011:06:27 16:40:00
exiftool "$f" |
awk -v f="$f" '
/^Create Date/ && $3 == ":" {
d = $4 ; t = $5
gsub(/:/,"-",d)
printf "touch -d \"%s %s\" %s\n", d, t, f
}
'
done


If the displayed output of the script is correct pipe it into sh.

Janis
Janis Papanagnou
2011-08-08 18:14:20 UTC
Permalink
Post by Janis Papanagnou
Post by Michael Hufschmidt
Hi Folks,
there exists a nice command line utility "exif" which can read (and set) exif
data from .jpg pictures. On the oter hand I can set the file creation date
with the command "touch". Now I want to set all file dates of pictures in the
current directory to the exif date and time. How could I do that in a shell
script?
Thanks in advance for any suggestions - Michael
Here's something that I once wrote and found in my ~/bin directory...
do
# Create Date : 2011:06:27 16:40:00
exiftool "$f" |
awk -v f="$f" '
/^Create Date/ && $3 == ":" {
d = $4 ; t = $5
gsub(/:/,"-",d)
printf "touch -d \"%s %s\" %s\n", d, t, f
}
'
done
If the displayed output of the script is correct pipe it into sh.
If you have spaces in your filenames you may have to add another pair
of escaped quotes \" around the final %s.

printf "touch -d \"%s %s\" \"%s\"\n", d, t, f
Post by Janis Papanagnou
Janis
Eric
2011-08-08 18:23:17 UTC
Permalink
Post by Michael Hufschmidt
Hi Folks,
there exists a nice command line utility "exif" which can read (and set)
exif data from .jpg pictures. On the oter hand I can set the file
creation date with the command "touch". Now I want to set all file dates
of pictures in the current directory to the exif date and time. How
could I do that in a shell script?
Thanks in advance for any suggestions - Michael
I assume you might be thinking of exiftool (
http://www.sno.phy.queensu.ca/~phil/exiftool/ )

which will do:

exiftool "-DateTimeOriginal>FileModifyDate" *.jpg

(and all sorts of other wonderful things). The quotes are _essential_ .

Probably in the package system for most Linux variants.

HTH

Eric
--
ms fnd in a lbry
Michael Hufschmidt
2011-08-09 09:10:59 UTC
Permalink
Post by Michael Hufschmidt
Hi Folks,
...
Post by Michael Hufschmidt
How could I do that in a shell script?
Eric, Janis, Lew and John: Thank you!
You are right, why should I re-invent the wheel? The exiftool was
included in my (openSUSE) distribution though not yet installed. And
yes, this exactly does what I want.

Isn't the newsgroup an excellent medium?

Michael :-)

Continue reading on narkive:
Loading...