|
GNU/Linux Desktop Survival Guide
by Graham Williams |
|
|||
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* |