Bash Script To Produce Exif Files From Batch of JPGs

Here's how to produce an exif text (or xml) file for each corresponding jpeg image in a directory of jpgs. You will end up with:

	image1.exif
	image1.jpg
	image2.exif
	image2.jpg
	image3.exif
	image3.jpg
		

I needed to do this when I was editing certain photography web pages. I'm sure there's an easier way to do this with one command line using find and xargs, but this does the trick for me. You will need to have installed the exif module on your linux box for this to work.

#!/bin/bash

for filename in *.jpg
do
	exif $filename > $filename.exif
done;

for i in *.jpg.exif
do
	j=`echo $i | sed 's#.jpg.exif#.exif#g' - `
	mv $i $j
done			

To produce xml files instead, add a -x after the exif command and change .exif to .xml accordingly.

Page Updated 16/04/09