25
\$\begingroup\$

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?

\$\endgroup\$
1

6 Answers 6

29
\$\begingroup\$

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' .

The -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.

Finally, the . 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 000 and 001.

\$\endgroup\$
2
  • \$\begingroup\$ Is it possible to add the copy number only when necessary? I would like to have most of the files named like 20181226-1734.nef and have the number suffix only when it was required because of the collission with other file. \$\endgroup\$
    – fracz
    Sep 9, 2019 at 16:50
  • \$\begingroup\$ @fracz EXIFTool has some ways to do things conditionally; check the docs. \$\endgroup\$
    – Blrfl
    Sep 9, 2019 at 18:22
11
\$\begingroup\$

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 20181226-DSC_0596.jpg.

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 -autorot and -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.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ The problem with jhead is it requires libjpeg-turbo-progs, so it will conflict with packages that require libjpeg-progs. \$\endgroup\$
    – xiota
    Dec 26, 2018 at 18:38
  • \$\begingroup\$ @xiota That sounds like a distro-specific packaging problem. If I recall correctly, in Fedora we just replaced libjpeg across the board. \$\endgroup\$
    – mattdm
    Dec 26, 2018 at 21:31
  • \$\begingroup\$ I upvoted your answer b/c it's a good solution if it works. Just wanted to note that there might be issues installing it. \$\endgroup\$
    – xiota
    Dec 26, 2018 at 23:38
  • \$\begingroup\$ @xiota What operating system is this a problem on? \$\endgroup\$
    – mattdm
    Dec 27, 2018 at 10:28
4
\$\begingroup\$

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 3nc to 4nc, the numeric value = how many digits to use).

Using the -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.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks a lot @tom-brossman, used your example and tweaked it and it scratched my itch of renaming the files to format used by Dropbox with duplicate renaming. Much appreciated! #!/bin/bash exiftool -fileOrder DateTimeOriginal -recurse -extension jpg -ignoreMinorErrors '-FileName<CreateDate' -d "%Y-%m-%d %H.%M.%S%%-c.%%e" "$@" \$\endgroup\$ Jan 28, 2022 at 19:49
  • \$\begingroup\$ If exiftool isn't available, apt-get install libimage-exiftool-perl might help you. \$\endgroup\$ Jul 24, 2022 at 9:11
2
\$\begingroup\$

Thanks all but I ended up using AmoK EXIF Sorter, a free app that does it all simply, quickly and effectively.

\$\endgroup\$
2
  • \$\begingroup\$ Hi Simon, welcome to Photo.SE. I'm glad you found a solution that works for you. If you don't mind, please mark your answer as the accepted answer (it's perfectly OK to ask and answer your own question). Thanks, and happy shooting! =) \$\endgroup\$
    – scottbb
    Dec 27, 2018 at 20:54
  • \$\begingroup\$ Such a shame it doesn't allow "folder name" as an option. Makes it useless for my needs as sometimes the only way I know what a photo series is about is the folder! \$\endgroup\$ Nov 3, 2020 at 11:25
2
\$\begingroup\$

Let me share a simple, wonderful and free tool that I have just used to rename a mess of several hundreds of pictures to their taken dates - it is called Namexif. What I had to do manually is to rename the containing folders, but after that tool that was ok for me. enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ In fact, the "Bulk Rename Utility - Free File Renaming Software" cannot be surpassed by anything. \$\endgroup\$
    – off-signer
    Aug 9, 2022 at 6:35
1
\$\begingroup\$

I had this problem with iCloud photos, for which Apple sets the download date to creation date (argh). Here my workflow with the free EXIFtool (long live to its author) steps to correct the date (set original date to creation date) and then use this data to rename according to the date:

  1. select all, and download = all are zipped into a folder (iCloud Photos), and unzipped on my harddrive (/DOWNLOAD LOCATION/FOLDER NAME).
  2. exiftool -fileOrder DateTimeOriginal -recurse -extension jpg -ignoreMinorErrors '-FileName<CreateDate' -d %Y-%m-%d%%-.2nc.%%e "$@" /DOWNLOAD LOCATION/FOLDER NAME
  3. exiftool "-filecreatedate<createdate" /DOWNLOAD LOCATION/FOLDER NAME
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.