Sunday, March 20, 2011

Rename Photos With Exiftool

There are a lot of usage examples for the powerful command line interface utility called Exiftool by Phil Harvey http://www.sno.phy.queensu.ca/~phil/exiftool/ but it took me a while to figure out the exact syntax to accomplish what I wanted to do. The following renames files (you can specify all writable files in a directory name at the end of the command, a pattern based on wildcards like *.JPG, or even one specific file) to something like 2011-02-20_03-05-41-1_NIKON D40.JPG (where filename is composed of date, time, "-" counter (the "." in the "%%-.c" causes the counter to start display "0" for non-duplicate filenames), EXIF Model tag, and original extension. THIS COMMAND DOES NOT LEAVE THE ORIGINAL FILENAME (it is like a "mv" not a "cp") :

exiftool '-FileName<${DateTimeOriginal}_$Model.%e' -d %Y-%m-%d_%H-%M-%S%%-.c ./DSC_1703.JPG

Yes, the filename has a space in it because the EXIF Model tag has a space in it, but if you're like I am and don't want spaces, it's easy enough to cleanse all the spaces from your filenames (in this case, with underscores) using the following command:

rename 's/ /_/g' *.JPG

Other tags besides Model can be used, too; I happen to want my filenames with Model in them. Of course one can combine these into one shell script called something like rename-myphotos.sh. It could look something like this:

#! /bin/bash
#
# Rename photos to something like:
# 2011-02-20_03-05-41-1_NIKON D40.JPG where filename is composed
# of date, time, "-" counter (the "." in the "%%-.c" causes the
# counter to start display "0" for non-duplicate filenames), EXIF
# Model tag, and original extension. THIS COMMAND DOES NOT LEAVE THE
# ORIGINAL FILENAME (it is like a "mv" not a "cp")
#
# Can replace ./ at end with directory name, filename, or filename
# pattern with wilcards.
#
# REMOVE "-n" FROM "rename" AND ADJUST FILENAME PATTERN AT END OF
# THAT LINE AS NECESSARY

exiftool '-FileName<${DateTimeOriginal}_$Model.%e' -d %Y-%m-%d_%H-%M-%S%%-.c ./
rename -n 's/ /_/g' ./

Wednesday, March 16, 2011

Easy CLI Commands for CD-ROM

To get information about CD media in a drive:

cdrecord -atip

To record a CD ISO image (i.e. the latest Linux release):

cdrecord -v the-filename.iso

Note: wodim is interchangeable with cdrecord.
Note: You may have to specify your optical drive by including, for example, /dev/cdrom in the above commands.