# Linux – Sort and rename images by date in EXIF info

exifimagemagicklinuxrename

I have a mess in my photos folder; I want to sort them according to date in EXIF information and rename according to the date (like 001.jpg, 002.jpg and so on).

How can I do this in Linux? I have used ImageMagick for some basic bulk processing tasks before (converting and resizing, etc), is it possible to use it for this task?

You can use exiftool. For some reason the online manual does not contain the "RENAMING EXAMPLES" section which gave me the essential hint.

For JPG only files the following command invocation should do the job:

exiftool -r '-FileName<CreateDate' -d '%Y-%m-%d/%H_%M_%S%%-c.%%le' <yourFolder>


Explanation:

• -r is for recursion
• '-FileName<CreateDate' tells exiftool to rename the file accordingly to its EXIF tag CreateDate (you can try others like ModifyDate though)
• -d '%Y-%m-%d/%H_%M_%S%%-c.%%le' tells how to build the filename string from the date source "CreateDate" (the "%-c" will append a counter in case of file collisions, the "%le" stands for "lower cased file extension")
• Note: I used "-FileName<..." here for renaming the files and moving it to another folder within one step. The manual points out that you have to use the "-Directory<..." syntax for folder operations. It worked for me this way though.

You should spend some time reading the manual of this powerful tool. Maybe there is an even shorter way :D