Using ExifTool

Metadata Master

Article from Issue 169/2014
Author(s):

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

Figure 1: A simple bar chart generated from data obtained by ExifTool.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News