So here is an example script that will bulk rename image files to a standard that begins with the date and time that the image was taken according to the embedded EXIF data. It does some other stuff too. You will need to tweak it to your own needs. I include the camera name in the image name in case I have a date/time collision and because it helps me know who took the photo. It will also add a sequence number on the end of the name if there is a name collision.
You will need two command line tools: jhead
and exiftool
though you could amend it to use only one probably. It is a BASH script so should work wherever BASH and the two helpers can be run - I often run it on a Windows laptop using Cygwin.
#!/bin/bash
# Rename camera files to a standard
# jhead (jhead -n%Y-%m-%d %H-%M-%S-Camera Name.jpg)
# exiftool, exiv2, exif
case $1 in
--help|-h|-?)
echo ' '
echo 'Rename a folder full of files to match the date/time taken and the camera model:'
echo ' "IMG_0001.jpg" ==> "2007-05-30 13-24-05-Canon PowerShot A720 IS.jpg"'
echo ' Adds a letter to end of name if the result is not unique'
echo ' '
echo 'Please use as:'
echo ' rename.sh folderName [t]'
echo 'Where:'
echo ' folderName is absolute or relative to current folder'
echo ' t, if present prints the command that would be used'
echo ' '
echo 'Requirements:'
echo ' 1) jhead (detects camera type)'
echo ' 2) exiftool (renames non-jpg files)'
echo ' '
echo 'Use the following workflow:'
echo ' 1) Copy files and folders from the camera(s) to a temp folder'
echo ' 2) Run this against the temp folder and check the renames'
echo ' 3) Manually rename any left-overs'
echo ' 4) Add IPTC comments, locations, etc.'
exit
esac
if [ -z "$1" ]; then
#echo 'You need to specify the folder to work on (end with a trailing /)'
## use pwd instead
FOLDER="`pwd`"
else
FOLDER=$1
fi
if [ -x /usr/bin/jhead ]; then
# Check if starts with leading / if not, then prepend pwd for safety
# NB: Note the substring processing: ${varname:start:numChars}
if [ ${FOLDER:0:1} != '/' ]; then
FOLDER="`pwd`/$FOLDER"
fi
# Add trailing / if required
if [ ${FOLDER:${#FOLDER}-1:1} != '/' ]; then
FOLDER="$FOLDER/"
fi
echo "$FOLDER"
cd "$FOLDER"
# Make sure all files are writable
chmod +w *
# Turn upper case extensions into lower case <== CANCEL THIS, the case helps id the camera
#echo "rename 's/\.JPG$/.jpg/' *.JPG"
#/usr/bin/rename 's/\.JPG$/.jpg/' *.JPG
# The above seems to have stopped working for some reason, try this instead
#echo "/usr/bin/rename '.JPG' '.jpg' *.JPG"
#/usr/bin/rename '.JPG' '.jpg' *.JPG
## REPLACE jhead WITH exiftool
ARTIST1=" '-IPTC:By-line=Julian Knight, http://www.knightnet.org.uk/contact.htm?toname=JulianPhotos' "
ARTIST2=" '-IPTC:By-line=James Knight, http://www.knightnet.org.uk/contact.htm?toname=JamesPhotos' "
COPYRIGHT=" '-IPTC:CopyrightNotice<Copyright © ${CreateDate} Julian Knight, all rights reserved' -d '%Y' "
## IPTC meta (Creator, Rights in XMP)
## Move to folders: ./mm-mmm
echo "jhead -model A70 -exonly -nf'%Y-%m-%d %H-%M-%S-Canon PowerShot A70' -ft *.jpg"
jhead -model A70 -exonly -nf'%Y-%m-%d %H-%M-%S-Canon PowerShot A70' -ft *.jpg
echo "jhead -model A720 -exonly -nf'%Y-%m-%d %H-%M-%S-Canon PowerShot A720 IS' -ft *.jpg"
jhead -model A720 -exonly -nf'%Y-%m-%d %H-%M-%S-Canon PowerShot A720 IS' -ft *.jpg
echo "jhead -model A720 -exonly -nf'%Y-%m-%d %H-%M-%S-Canon PowerShot A720 IS' -ft *.JPG"
jhead -model A720 -exonly -nf'%Y-%m-%d %H-%M-%S-Canon PowerShot A720 IS' -ft *.JPG
echo "jhead -model Hero -exonly -nf'%Y-%m-%d %H-%M-%S-MDA Compact III' -ft *.jpg"
jhead -model Hero -exonly -nf'%Y-%m-%d %H-%M-%S-MDA Compact III' -ft *.jpg
echo "jhead -model T8282 -exonly -nf'%Y-%m-%d %H-%M-%S-HTC Touch HD' -ft *.jpg"
jhead -model T8282 -exonly -nf'%Y-%m-%d %H-%M-%S-HTC Touch HD' -ft *.jpg
echo "jhead -model DCR-PC120E -exonly -nf'%Y-%m-%d %H-%M-%S-Sony DCR-PC120E' -ft *.jpg"
jhead -model DCR-PC120E -exonly -nf'%Y-%m-%d %H-%M-%S-Sony DCR-PC120E' -ft *.jpg
echo "jhead -model D90 -exonly -nf'%Y-%m-%d %H-%M-%S-NIKON D90' -ft *.JPG"
jhead -model D90 -exonly -nf'%Y-%m-%d %H-%M-%S-NIKON D90' -ft *.JPG
# James' Samsung S860 Make: Samsung Techwin, Model: <KENOX S860 / Samsung S860>
echo "jhead -model S860 -exonly -nf'%Y-%m-%d %H-%M-%S-Samsung S860' -ft sdc?????.jpg"
jhead -model S860 -exonly -nf'%Y-%m-%d %H-%M-%S-Samsung S860' -ft sdc?????.jpg
#exiftool '-if $make eq "Samsung Techwin"' '-if $model eq "<KENOX S860 / Samsung S860>"' -overwrite_original_in_place sdc?????.jpg
# Deal with .NEF (Nikon Raw) files (rename to YYYY-MM-DD HH-MM-SS-NIKON D90-DSC_????.NEF)
exiftool '-FileName<${CreateDate}-NIKON D90-%f.%e' -d '%Y-%m-%d %H-%M-%S' DSC_????.NEF
# Use %c to add seq num where required
# Deal with .AVI files (rename to YYYY-MM-DD HH-MM-SS-NIKON D90-DSC_????.AVI)
exiftool '-FileName<${FileModifyDate}-NIKON D90-%f.%e' -d '%Y-%m-%d %H-%M-%S' DSC_????.AVI
# Deal with .AVI files (rename to YYYY-MM-DD HH-MM-SS-Samsung S860-sdc?????.avi)
exiftool '-FileName<${FileModifyDate}-Samsung S860-%f.%e' -d '%Y-%m-%d %H-%M-%S' sdc?????.avi
echo ' '
echo 'FINISHED RENAME'
echo ' '
else
echo 'You need to install jhead first'
fi
Note that you will need to find out what Maker name your camera uses in the EXIF data and change the commands appropriately if you want to include a camera name.
Run this against each folder of images and you should end up with them all named in such a way as they will always sort by name into the order in which they were taken no matter what the OS or other tools do to the file creation and modification dates. Note that you can never really trust these anyway since there are any number of reasons why they may change (for example the creation dates may get reset after some copy/move commands).
yyyy-mm-dd--hh-mm-ss--camera_name.xxx
. That is done using a script that reads the EXIF date info so that the images always sort by name into date/time order even if something later edits them and changes the modify date. I would never rely on the OS's file date. I can add an answer that shows you how to do this if you like. Let me know.