Go to TogaWare.com Home Page. GNU/Linux Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

Rename Photos

Here we rename the filenames of the photos in our collection of photos using a standard format of four a digit year, two digit month, two digit day, then hour, minutes and seconds, and then a sequential count starting at 00, each segment separated by an underscore:

YYYYMMDD_HHMMSS_NN.jpg

For a folder of photos we can find those that do not match the naming scheme with the regular expression below. This find command identifies regular files (-type f), using a sed type regular expression. The -regex here matches any prefix (path) and then 8 digits, underscore, 6 digits, underscore, two digits and then the file type.

$ find . -type f -regextype sed -not -regex '.*[0-9]\{8\}_[0-9]\{6\}_[0-9]\{2\}\.jpg'

We can use exiftool from the exiftool package to rename image files based on the meta data contained within the file itself.

First test the renaming that will take place. The %%-c will add -1, for example, if the new file already exists and %%le converts the original extension to lowercase.

$ exiftool -d %Y%m%d_%H%M%S_00%%-c.%%le "-testname<CreateDate" IM* 

Then do the actual renaming, adding a verbose option -v and changing -testname to -filename:

$ exiftool -v -d %Y%m%d_%H%M%S_00%%-c.%%le "-filename<CreateDate" IM*

If the CreateDate is not present the FileModifyDate might be:

$ exiftool -v -d %Y%m%d_%H%M%S_00%%-c.%%le "-filename<FileModifyDate" IM*


Support further development by purchasing the PDF version of the book.
Other online resources include the Data Science Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 1995-2020 Togaware Pty Ltd. Creative Commons ShareAlike V4.