It happens sometimes… or at least: it happened to me, and maybe it happened to you also 🙂 Well, anyway, it happens that you get a number of digital photos from different people, and of course their filenames don't match their chronological order. Is it possible to rename the files so that they can help sort this mess? Well, it is!
First, you need a small command line utility called exif. I assume you have an idea of what EXIF is.
With this command it is really easy to extract exif information from a digital photo, for example: the date you took the photo:
$ exif -t 0x9003 LD2K10_005.JPG EXIF entry 'Data e ora (dati originali)' (0x9003, 'DateTimeOriginal') exists in IFD 'EXIF': Tag: 0x9003 ('DateTimeOriginal') Format: 2 ('Ascii') Components: 20 Size: 20 Value: 2010:10:23 08:29:01
We have all the information we need, and maybe more. Now we need to get the information in the Value field, mangle it to a more "filename-friendly" format, and rename the file. And it's not that hard:
for FILE in *.JPG do NEW=$(exif -t 0x9003 $FILE | awk '/Value/' | sed -e 's/^ Value: //' -e 's/://g' -e 's/ /-/') NEW="$NEW-$FILE" mv -v "$FILE" "$NEW" done
The snippet above actually fits a one-liner:
for FILE in *.JPG ; do NEW=$(exif -t 0x9003 $FILE | awk '/Value/' | sed -e 's/^ Value: //' -e 's/://g' -e 's/ /-/') ; NEW="$NEW-$FILE" ; mv -v "$FILE" "$NEW" ; done
Good luck!