Category ArchiveUncategorized
Uncategorized 03 Aug 2009 12:26 am
Renaming jpegs using EXIF data
Here’s a handy bash snippet I just got done using to rename a bunch of jpegs that had their ctimes/atimes mangled. This resets the time to whatever the createtime is in the EXIF data, and renames the file to something meaningful (if you used an undelete program that spits out random filenames). Enjoy.
#!/bin/bash
find /home/maxvend/recover -type f -iname \*.jpg | while read names; do
#Extract the exif create date
ctime=`exiftool -dateFormat "%Y-%m-%d %T" -CreateDate $names | cut -d: -f2-6`;
#set the atime, mtime
touch -cma --date="$ctime" $names;
#Rename the file to something meaningful.
newname=/home/maxvend/recover/`ls --full-time -Gg $names | awk -F" " '{print $4 " " $5}' | xargs -I xx date --date="xx" +%Y-%m-%d-%H%M%S`"_picture.jpg"
if [ -e $newname ]; then
cp -pv $names $newname.2
else
cp -pv $names $newname
fi
done;