$ identify -verbose *.jpg | grep exif:Model | sort | uniq
On the directory where the pictures were, redirecting the output to the sort and uniq filters gave us the list of cameras used by the photographer. As you may know, the '$' sign at the beginning of the line is the prompt of the shell, not a part of the command.
exif:Model: NIKON D3X
exif:Model: NIKON D810
$ identify -verbose 141.jpg | grep DateTimeOriginal
This, together with the previous use of identify, revealed us that the camera NIKON D810 used by the photographer had both the wrong time and date set. i.e. 2014:04:21 instead of 2015:06:07.
$ identify -verbose *.jpg | grep DateTimeOriginal | sort | uniq -c
The effect of running uniq with the -c flag is to add a number in front of each line counting the number of repeated lines. We were surprised to see that this happened 7 times. So, for avoiding deleting files by using the same name twice, we changed the generated file names into the next format: procession-date-time-camera-basename.jpg where basename is that part of the file name that is stripped from its prefix (the path to the file, if present) and suffix (.jpg here).
$ date --date='now + 40 hours'
This arithmetic on dates only works on the GNU versions of date. So BSD and OS X users cannot access this feature in the way I describe here.
$ date +"%Y:%m:%d %H:%M:%S" -d '2014/04/21 5:42:36 +0200'
The +0200 argument is to be used in Western Europe during the summer. The output of the above command gives:
2014:04:21 05:42:36
date +"%Y:%m:%d %H:%M:%S" -d '2014/04/21 5:42:36 +0200 + 1 year + 2 months - 14 days + 4 hours + 20 min'
This gives us the result we hoped. See the output below.
2015:06:07 10:02:36
#!/bin/bash
destdir=renamed-files
rm -f $destdir/*
for pict in *.jpg ;
do basename=$(basename $pict .jpg)
camerainfo=$(identify -verbose $pict | grep exif:Model)
# strip begin of line from camerainfo
camera=${camerainfo/ exif:Model: /}
# change spaces into underscores in camera
camera=${camera// /_}
shotdatetimeinfo=$(identify -verbose $pict | grep DateTimeOriginal)
# strip begin of line from shotdatetimeinfo
shotdatetime=${shotdatetimeinfo/ exif:DateTimeOriginal: /}
# format date as suitable input for date command, separator is "/"
shotdate=${shotdatetime:0:10}
shotdate=${shotdate//://}
# format time is suitable as input for date command, separator is ":"
shottime=${shotdatetime:11:8}
# correct date and time here, according to camera
if [ $camera == "NIKON_D810" ]
then correctdate=$(date +"%Y%m%d" -d "$shotdate $shottime +0200 + 1 year + 2 months - 14 days + 4 hours + 20 min")
correcttime=$(date +"%H%M%S" -d "$shotdate $shottime +0200 + 1 year + 2 months - 14 days + 4 hours + 20 min")
else # $camera == "NIKON_D3X"
correctdate=$(date +"%Y%m%d" -d "$shotdate $shottime +0200 + 1 hour")
correcttime=$(date +"%H%M%S" -d "$shotdate $shottime +0200 + 1 hour")
fi
cp $pict $destdir/procession-$correctdate-$correcttime-$camera-$basename.jpg
done
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (1)
Author
Commented:Thanks for fixing the typos.
You said:
I would be happy to know what I have to do to get this done.
Thanks in advance.