Categories
General

Image renaming bash script

As part of my photo archiving process I like to first change the image file names from their original nonsense names to something based on the date and time. This way, if I upload a low-res image someplace, such as Flickr, I can easily use its original filename to locate the high-res version in the archives. This also means all of my images have unique filenames.

To batch rename files, I used to use a script called “irename” that I got from varp.net a long time ago. Unfortunately, it would fail to rename images that were taken too close together. Looking at the code, it didn’t include a way to automatically give unique names to images taken really close together. So, I looked at the code to see if I could fix it. It turned out the script was parsing the EXIF info in image files itself – which I guessed an external program could do more reliably. There’s a Perl library and command-line tool called exiftool that does a great job of parsing EXIF info. It even does exactly the sort of image file renaming I wanted to do, but I didn’t want to have to type all this every time:

exiftool -d %Y%m%d_%H%M%S%%-c.%%e "-filename

When you find yourself typing stuff like this at the command line repeatedly, you should put it in a bash script with a name you’ll remember, place that in your “bin” folder, and make it executable. I called my script “camcon” because I didn’t have anything on my system with that name and it sounded easy to remember. Download camcon: camcon.zip

Avatar photo

By isaac

I like cats. he/him