I have around 3000 jpeg photos all with names like "
DSC_0596". The metadata has the date the photo was created, which would be much more useful.
Is there a way to extract the date from the metadata and add it to the photo name?
ExifTool is pretty much the Swiss army chainsaw for doing these kinds of things. It has a steep learning curve, but once you're over it, the kind of renaming you're after is a snap:
exiftool -d '%Y%m%d-%H%M%%-03.c.%%e' '-filename<CreateDate' .
-d switch tells ExifTool to format dates according to the next argument's pattern. The pattern contains date format codes that fill in various bits and pieces from the date. This would rename a file taken today at 17:34 to
20181226-1734-000.nef. The three zeros after the time are a copy number put there by
%%-03.c in the date format. I'll explain why that's important in a minute.
The next argument tells ExifTool to change the filename to whatever is in the
CreateDate field in the EXIF using the date format specified earlier.
. is the path of the directory where you want to operate. You can also specify individual images if you want.
About the copy number: This is an important thing to put in your filenames because many cameras don't provide fractional seconds in their timestamps. If you had multiple files created during the same second, each successive rename would overwrite the last file and all you'd get is the last one. When picking a name, ExifTool will keep incrementing the copy number until it finds a filename that doesn't exist and rename the file to that. Note that this does not weed out duplicates. If you use this method to copy images from a card into some other directory and then run it again on the same set of images, you will end up with identical files numbered
For simple things where the flexibility, power, and complication of ExifTool aren't necessary, I like to use the tool jhead. It's a command-line tool available for Linux, Mac, and Windows.
jhead -n%Y%m%d-%H%M%S *.jpg
will automatically rename all files ending in
.jpg in the current directory to a format like
20181226-111141.jpg. You can use
%f to also include the original filename (without extension). So, for example:
jhead -n%Y%m%d-%f *.jpg
... which gives the date (and not the time) and the original filename, like
Note that there is logic to attempt to not rename files which already are mostly digits, which keeps the command from accidentally acting twice. Use
-nf instead of just
-n to override this. There is also logic to automatically add an incrementing trailing digit if the target filename already exists.
Also, I usually add
-ft to the command line, to match image orientation to the camera's rotation sensor and to make the file time match the exif time.
I use the following script, placed in ~/.local/share/nautilus/scripts (this should work for any Linux distro using Nautilus as a file manager):
#!/bin/bash exiftool -fileOrder DateTimeOriginal -recurse -extension jpg -ignoreMinorErrors '-FileName<CreateDate' -d %Y-%m-%d%%-.3nc.%%e "$@"
Doing it this way means I can select one or more files/directories and recursively rename all JPEG images in them from my mouse's right-click menu, which is pretty handy. It also ignores any files that are not JPEGs so I do not need to worry about what is in subdirectories.
Selected files are renamed in the following pattern YYYYMMDD-001.jpg. Numbering begins at 001 and continues to 999, so if you shoot 1000 or more images in one day you must modify the script (change
4nc, the numeric value = how many digits to use).
-fileOrder DateTimeOriginal argument makes sure that images are processed in order, and numbering strictly follows that order, otherwise shots takes in quick succession are not guaranteed to be renumbered in exact order they were taken.
Thanks all but I ended up using AmoK EXIF Sorter, a free app that does it all simply, quickly and effectively.