I am looking to analyze my library of photos to see what focal lengths I use most often, to better inform lens purchasing decisions.

The recommendations I have been able to find online so far usually advise downloading specific software applications or editing software.

I am hoping to find more examples of people who have written code that interacts directly with the photo files in the file tree by looping over the metadata. I have found attempts of people doing this, but never have been able to track down the source code.

Any recommendations? I am looking for a starting point as I don't have much experience with bash scripting or using python for file traversal.

  • \$\begingroup\$ I think it's important when doing something like this to be consious of the possibility that duplicates (i.e. photos taken in quick succession) can skew the data. Crude example... Say you took 20 photos in your life, but 10 of them were of a deer in your back yard, taken in quick succession with a 300mm lens. You had just been trying to capture one scene nicely, but the data makes it look like you want a 300mm lens for 50% of your shots. \$\endgroup\$
    – osullic
    Commented Sep 23, 2022 at 19:17
  • \$\begingroup\$ @osullic I would expect such statistics to be done on a properly culled photo collection. \$\endgroup\$
    – xenoid
    Commented Sep 24, 2022 at 23:57

3 Answers 3


On my collection using Unix shell commands and exiftool:

Sorted by focal length:

find . -name 'IMG_????.JPG' -exec exiftool -FocalLength  -p '$FocalLength' {} + | sort -n | uniq -c 

Sorted by frequency:

find . -name 'IMG_????.JPG' -exec exiftool -FocalLength  -p '$FocalLength' {} + | sort -n | uniq -c | sort -n 

In slo-mo:

  • find . -name 'IMG_????.JPG: all matching files under current directory (you may have to change the pattern for other naming schemes). Using this kind of pattern avoids counting twice (JPG and CR2 for me).
  • -exec exiftool -FocalLength -p '$FocalLength': extract focal length
  • {} +: process as much as possible is one exiftool invocation
  • | sort -n: sort numerically (so '90 mm' is before '100 mm')
  • | uniq -c: replace consecutive equal occurrences by single line with count
  • | sort -n: (optional) sort on count


    271 10.0 mm
      9 10.2 mm
      5 10.5 mm
      3 10.8 mm
     65 11.0 mm
     10 11.3 mm
      7 11.6 mm
      3 11.9 mm
     34 12.0 mm
      9 12.2 mm
      7 12.5 mm
      3 12.8 mm
     33 13.0 mm
      3 33.0 mm
      1 33.3 mm
    215 34.0 mm
    653 35.0 mm
      6 36.0 mm
    119 37.0 mm
     75 38.0 mm
    192 58.0 mm
      5 60.0 mm
    187 63.0 mm
      7 65.0 mm
   1661 70.0 mm
     12 74.0 mm
     12 79.0 mm
      9 84.0 mm
     15 90.0 mm
     12 96.0 mm
    745 100.0 mm
     15 109.0 mm
     12 116.0 mm
    367 120.0 mm
     15 123.0 mm
    191 251.0 mm
    247 273.0 mm
    194 297.0 mm
    185 323.0 mm
    181 352.0 mm
    686 400.0 mm
      1 417.0 mm
      1 454.0 mm
     12 495.0 mm
     32 560.0 mm

2'30" elapsed on 12000 pictures (Core [email protected], from SSD)

With a strong influence of my two macro prime lenses (35mm and 100mm), my 17-70mm often used as its longest, and my 120-400mm often used at either end, and the occasional 120-400mm on 1.4x extender.


Combination of exiftool and awk for example can do the work:

$ exiftool -FileName  -FocalLength  -p '$FileName:$FocalLength'  -r . 2>/dev/null |awk -F: '!/xmp/ {gsub(/ mm/,"");a[$2]+=1} END {for (k in a) print k","a[k]}'

This command will provide result like:


and from there you can use some program to produce fancy graphic like in your examples.

If you work on Windows OS you can check this page for installation of awk.

And one idea from comment how to do it w/o awk:

exiftool -FocalLength  -p '$FocalLength'  -r . 2>/dev/null|grep -vi xmp| sort | uniq -c
  • 2
    \$\begingroup\$ If you need a "Windows" installation of awk, it's almost certain the best solution these days is WSL. \$\endgroup\$
    – Philip Kendall
    Commented Sep 23, 2022 at 7:21
  • \$\begingroup\$ @PhilipKendall, honestly do not have much experience with WSL. Prefer to use virtual machines. :) \$\endgroup\$ Commented Sep 23, 2022 at 7:22
  • 1
    \$\begingroup\$ Getting well off-topic here, but I'd recommend at least trying WSL - WSL v2 is effectively a virtual machine (it runs a Linux kernel), just one which integrates very nicely with the host OS. \$\endgroup\$
    – Philip Kendall
    Commented Sep 23, 2022 at 7:39
  • 1
    \$\begingroup\$ Awk-less version (also doesn't print the filename to remove it downstream): exiftool -FocalLength -p '$FocalLength' -r . | sort | uniq -c \$\endgroup\$
    – xenoid
    Commented Sep 23, 2022 at 8:17
  • 1
    \$\begingroup\$ @RomeoNinov I didn't say "unix-less" but "awk-less" :) \$\endgroup\$
    – xenoid
    Commented Sep 23, 2022 at 8:25

I suspect you want a more statistical answer than what I'm about to suggest, but I'll offer it anyway in case it's of use.

I use digiKam to manage my digital photo collection, and I've also given a rating (one to five stars) to most of the photos I've ever taken. Once you've got a big bunch of star-rated photos taken with a digital camera, you can use digiKam's impressively configurable search to ask it to find all images taken with focal lengths between (for example) 16mm and 35mm. Then you can also use the digiKam quick filters to show only images rated four stars or higher.

This gives a quick way to find out not only how many images you've taken within a bunch of focal length intervals, but also gives a good idea of what percentage of those images you liked enough to rate them four or five stars. This might reveal that you are overall more satisfied with your telephoto shots than you are with your ultra-wide shots, or that you've largely ignored your two-grand 50mm f/1.2 professional lens and stuck with your second-hand 24mm tilt-shift lens.

If you need to be able to do some statistical analysis of your focal lengths, then this approach may not be useful to you. (Though if you shove your counts into a spreadsheet you can still come up with a nice histogram or bar chart.)


Your Answer

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

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