Quick Script To Sort and Rename from EXIF Date

I wrote a quick bourne shell script to sort and rename the image files I recovered from my formatted memory stick. It requires the perl exifdump script that comes with the Image::Info module (not the python script by the same name). Since the last pre-format image I had was 8160, I started the recovered files at number 8161. The filenames will not be exactly right due to images that were deleted and retaken, but close enough.

The script was coded up quickly so there is no documentation or error checking.


TEMPLIST=`/usr/local/bin/mktemp /tmp/ds-rename.XXXXXX`
TEMPSORT=`/usr/local/bin/mktemp /tmp/ds-rename.XXXXXX`

for file in V*.[jJ][pP][gG]
echo "Processing ${file}..."
DATE=`/home/jlick/bin/exifdump ${file} 2> /dev/null | /bin/grep DateTimeOriginal | /bin/sed -e "s/.*DateTimeOriginal -> //"`
echo ${DATE} ${file} >> ${TEMPLIST}

echo "Sorting..."
/bin/sort ${TEMPLIST} > ${TEMPSORT}

for file in `/bin/sed -e "s/.* //" < ${TEMPSORT}`
echo "Renaming ${file} to ${PRE}${NUM}${EXT}..."
/bin/mv ${file} ${PRE}${NUM}${EXT}
NUM=`/bin/expr ${NUM} + 1`

/bin/rm -f ${TEMPLIST} ${TEMPSORT}

3 thoughts on “Quick Script To Sort and Rename from EXIF Date”

  1. You may wish to use Image::ExifTool instead of Image::Info as the latter has not been maintained for quite some time now. I’m sure CPAN will probably keep it forever and since you don’t need more advanced tags, it probably doesn’t matter. Still, something to keep in mind.

  2. Yeah, but I already had exifdump and Image::Info installed and know basically how it works. (This script is basically a rewrite of ds-makeslide so a lot of the code was borrowed.)

Leave a Reply

Your email address will not be published. Required fields are marked *