…or how to include the data and time of the photo in its filename
On [LBo] sombody wrote:
My digital camera maintains an internal count of exposures to date which it then uses to name the images. This leads to such useful image names as 100_0473.JPG. Once downloaded to the computer, I’d like to rename the set of images to something more meaningful like this:
100_0473.JPG → nature-hike_0001.jpg
100_0474.JPG → nature-hike_0002.jpg
[…]
There is a wonderful utility for mass renaming of files. I use it to conver the capital “.JPG” to “.jpg” on all pictures before continueing:
stw@notebook:~$ mmv "*.JPG" "#1.jpg"
Now I use the “exif” command to get the information about when the picture was taken:
stw@notebook:~$ LANG=C exif -m -t "Date and Time" sample.jpg
EXIF entry 'Date and Time' (0x132, 'Date and Time') exists in IFD '0':
Tag: 0x132 ('DateTime')
Format: 2 ('Ascii')
Components: 20
Size: 20
Value: 2007:02:15 12:37:17
The “LANG=C” before the actual command ensures that the english locale is used, so it will work wherever you all are right now. The “exif” command then extracts the date and time of the snapshot, which I then can convert using “grep”, “cut” and “sed”:
stw@notebook:~$ LANG=C exif -m -t "DateTime" sample.jpg \ | grep "Value:" | cut -c 10-28 | sed -e "s/://g" -e "s/ /-/" 20070215-123717
Now we have a format which does not “look good” but makes sure that there should be no duplicate filenames: The camera counts the pictures, and the date and time should also be pretty unique. Even if you collect pictures taken by more than one camera on one harddisk, the likelyness of taking two pictures with the same running number at the same second should be small enough for most purposes.
We can put all of this together into a “for”-loop along with a “mv” and we are set:
stw@notebook:~$ for PIC in *.jpg ; do \ mv -v $PIC $(LANG=C exif -m -t "Date and Time" $PIC | \ grep "Value:" | cut -c 10-28 | sed -e "s/://g" -e "s/ /-/")-$PIC \ ; done
and if we want more information in the filename, we can tweak the “mv” to have :
stw@notebook:~/some-pics$ for PIC in *.jpg ; do mv -v $PIC \ Gone-Fishing_$(LANG=C exif -m -t "Date and Time" $PIC | \ grep "Value:" | cut -c 10-28 | \ sed -e "s/://g" -e "s/ /-/")-$PIC-snapshop-by-me.jpg\ ; done „IMG_5355.jpg“ -> „Gone-Fishing_20070218-122214-IMG_5355.jpg-snapshop-by-me.jpg“ „IMG_5356.jpg“ -> „Gone-Fishing_20070218-122308-IMG_5356.jpg-snapshop-by-me.jpg“ „IMG_5357.jpg“ -> „Gone-Fishing_20070218-122316-IMG_5357.jpg-snapshop-by-me.jpg“ „IMG_5358.jpg“ -> „Gone-Fishing_20070218-122321-IMG_5358.jpg-snapshop-by-me.jpg“ „IMG_5359.jpg“ -> „Gone-Fishing_20070218-122336-IMG_5359.jpg-snapshop-by-me.jpg“ „IMG_5360.jpg“ -> „Gone-Fishing_20070218-122339-IMG_5360.jpg-snapshop-by-me.jpg“ „IMG_5361.jpg“ -> „Gone-Fishing_20070218-122344-IMG_5361.jpg-snapshop-by-me.jpg“ „IMG_5362.jpg“ -> „Gone-Fishing_20070218-125624-IMG_5362.jpg-snapshop-by-me.jpg“
…and then we need to use “mmv” just one more time:
mmv "*.jpg*.jpg" "#1#2.jpg"
Now combine this with what is in Stamped and Categorized and we have a nice, customized script which automates the “import” of pictures taken.
As you can see, I just LOVE long filenames which contain just about everything there is to know about the picture. With the “exif” command, we could even add data like exposure-time, aperture, resolution and the use of flashlight to the filename, but that could be a little bit too much :)
Copyright (c) by the authors.
Prior to editing, authors agreed to license their contributions by the terms of the GPL.
See our licensing page for details.
Linux® is a registered trademark of Linus Torvalds.