Jun 162009

Even when shooting images in raw format, it is typically easier to do simple sorting and sharing with jpg files. With Nikon *.nef raw files, it is possible to extract a full-resolution jpg image using the nefextract script. However, exif metadata is not automatically copied to this extracted jpg.

The tool that I use to manipulate my images according to their exif metadata is exiv2, and I can quite simply copy metadata from raw files to their corresponding jpgs (matching filenames, and all in the one working directory) with:

exiv2 insert -l./ -S.nef *.jpg

After sorting through the jpgs and deleting all but those worth keeping, I wanted to automatically remove the raw files of those deleted images. Sure enough, this is easily done with some bash shell magic:

for file in *??.jpg; do mv raw/${file%%.jpg}.nef 2> /dev/null rawKeep/ ; done

This command says “for each jpg file you find here, move the matching nef file from the subdirectory raw/ to the subdirectory rawKeep/”. I can then delete any files left in the raw/ subdirectory, as they mustn’t have a matching jpg.

People often ask my why I persevere with the “command line” (more technically the “shell”). It seems that they assume tools with graphical interfaces are more powerful and faster. These two routine tasks demonstrate yet again that the shell really is the most efficient way to do many common jobs.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>