Using ExifTool
Metadata Master
Understanding the full power of ExifTool can be daunting. We show how to put it to practical use.
ExifTool [1] has the well-deserved reputation of being a flexible and infinitely powerful utility for working with photographic metadata. Indeed, ExifTool can handle practically every metadata-related task you throw at it: from adding and removing tags to performing advanced actions based on specific values obtained from metadata. Despite its comprehensive documentation, however, coming to grips with ExifTool can sometimes be a daunting proposition. In this article, I provide a gentle introduction to ExifTool's capabilities and show how to put this excellent tool to practical use.
Inside almost every digital photo hides a wealth of useful metadata. Many photo management applications like digiKam and Darktable make it possible to view and edit metadata. As is often the case, however, even the most powerful graphical applications can't compete with command-line tools in terms of speed and efficiency. ExifTool is no exception. If you need to process hundreds, or even thousands, of photos on a regular basis, using ExifTool can save you a lot of time and effort. Even if you need to modify a handful of photos, doing so with ExifTool can be more efficient than resorting to your preferred photo management application.
Getting Started with ExifTool
The first step is obviously to install ExifTool on your system. Because the utility is available in the software repositories of many mainstream Linux distributions, it can be easily installed using your distro's package manager. On Debian and Ubuntu, deploying ExifTool is a matter of running the
apt-get install libimage-exiftool-perl
command as root. To see ExifTool in action, run the
exiftool /path/to/foo.jpg
command, which generates a long list of metadata tags and their values pulled from the source photo. Besides JPG, ExifTool can handle a wide range of other formats as well as RAW and video files (see the full list of supported formats on the project's website).
Metadata included in a digital photo actually comes from several different groups, including Exif (Exchangeable image file format maintained by the Japanese Electronics and Information Technology Industries Association), IPTC (standard developed by the International Press Telecommunications Council for the purpose of data exchange between newspapers and news agencies), MakerNote data (tags that allow camera manufacturers to add custom metadata), XMP (metadata stored in the XMP format originally created by Adobe Systems Inc.), and Composite (composite tags derived from the values of other tags).
Despite its name, ExifTool can handle metadata stored in all these formats. When you need to read or modify a specific tag in metadata, you occasionally need to know the actual name of the tag (as opposed to the human-friendly format used by default) and the group it belongs to. The easiest way to find that out is to use the exiftool
command with the -s
and -G
switches. The former shows the actual tag names, whereas the latter lists all tags organized by groups. Run the
exiftool -s -G /path/to/foo.jpg
command, and you should see a list of tags neatly organized into groups.
Rename and Organize Photos Using Metadata
Besides merely reading metadata, ExifTool can perform other useful actions. For example, the tool can read the photo's creation date and time and then use the obtained values to rename the file. The following command renames the foo.NEF
raw file in the current directory using the YYYYMMDD-HHMMSS.NEF
format (e.g., 19730915-153500.NEF):
exiftool -d %Y%m%d-%H%M%S.%%e '-FileName<DateTimeOriginal' /path/to/foo.NEF
The command consists of three parts. The -d
switch sets the format for date and time values, and the rule right after the switch defines the format itself (%%e
keeps the original file extension). The '-FileName<DateTimeOriginal'
part instructs ExifTool to obtain the creation date and time and use these values as the file name. The last part of the command specifies the path to the file.
You can use the path to a folder instead of a single file to run the command on all files in the target directory. For example, the following command processes all the photos in the current folder (. denotes the current working directory):
exiftool -d %Y%m%d-%H%M%S.%%e '-FileName<DateTimeOriginal' .
ExifTool supports a wide range of parameters and switches. The -ext
parameter, for example, can be useful when you need to process photos in a specific format. Say the target directory contains both JPG and NEF RAW files and you want to rename RAW files only; then, you can use the -ext NEF
parameter as follows:
exiftool -ext NEF -d %Y%m%d-%H%M%S.%%e '-FileName<DateTimeOriginal' .
The -r
switch can be used to run ExifTool commands on a directory and all its subdirectories:
exiftool -ext NEF -r -d %Y%m%d-%H%M%S.%%e '-FileName<DateTimeOriginal' .
Renaming photos is only one of ExifTool's many capabilities. Do you need to organize photos into folders by year? The command below provides a solution to the problem:
exiftool -r -d %Y '-directory<$DateTimeOriginal/%d' .
This command pulls the year from each photo's creation date and moves the photo into the appropriate folder (the folder is automatically created if it doesn't already exist).
Read and Analyze Metadata
ExifTool's ability to read values from metadata tags can be put to a variety of practical uses. As a photographer, you might be curious as to what focal length you shoot most. ExifTool can help you answer this question. The following command uses the -focallength
parameter to extract the lens and focal length information from photos in the current working directory and writes the obtained data to the focal_length_data.dat
text file:
exiftool -ext JPG -T -r -focallength . > focal_length_data.dat
Besides the -ext JPG
parameter, the command also uses the -T
switch, which outputs the result in tabular format, and the -r
switch, which instructs ExifTool to process all subdirectories recursively.
The list generated can give you a rough idea of what your most used focal lengths are, but you can massage the data using other tools to produce more meaningful results:
exiftool -ext JPG -T -r -focallength . | sort -g | uniq -c | sed -r 's/ \ {5}//g' > focal_length_data.dat
This command obtains the focal length values, which are then piped through the sort, uniq, and sed tools. The sort -g
command sorts the values in ascending order, and the uniq -c
command counts the number of each focal length value. Finally, the sed -r 's/ {5}//g'
command removes extra whitespace.
The fun doesn't have to stop here, though: Using the Gnuplot graphing tool [2], you can generate a chart that visualizes the processed data. For that, you need to install Gnuplot on your system and tweak the data. Installing Gnuplot on Debian and Ubuntu is a matter of running
apt-get install gnuplot
as root.
The focal length values obtained by ExifTool are formatted as strings: 35.0 mm
, 50.0 mm
, 85.0 mm
, etc. Before you feed the generated focal_length_data.dat
file into Gnuplot, you need to remove the .0 mm
part from the focal length values, so the graphing tool can read them. To do this, you can specify an additional replacement rule for the sed tool as follows:
exiftool -ext JPG -T -r -focallength . | sort -g | uniq -c | sed -r 's/ \ {5}//g;s/.0 mm//;' > focal_length_data.dat
Gnuplot is a powerful graphing tool that can produce impressive results, but you don't have to master all its advanced features to create simple graphs. Execute the gnuplot
command to enter the interactive Gnuplot shell, then run the following commands:
set terminal png set output "focal_length_data.png" set style fill solid plot "focal_length_data.dat" using 1: xtic(2) with histogram
This generates a simple bar chart in the PNG format (Figure 1).
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4
-
Fedora Unleashes Atomic Desktops
Fedora has combined its solid distribution with rpm-ostree system to make it possible to deliver a new family of Fedora spins, called Fedora Atomic Desktops.
-
Bootloader Vulnerability Affects Nearly All Linux Distributions
The developers of shim have released a version to fix numerous security flaws, including one that could enable remote control execution of malicious code under certain circumstances.