• CLI

Metadata Management with ExifTool

ExifTool is a powerful command-line utility for reading and modifying metadata in files. Explore its basic usage and some useful applications.

Written by Jacob Gelman

What is metadata?

Metadata is the additional information embedded in digital files, describing the content, quality, and other characteristics of the data. Some examples of meta tags include file creation and modification dates, technical specifications (like resolution and file format), descriptive tags (like titles and authors), and even GPS coordinates for photos.

Some meta tags are essential for a file to be read correctly whereas others are present for organizational or informational purposes; a photo's resolution must be accurately specified in its metadata in order for the pixel data within the file to be interpreted correctly whereas GPS coordinates, if present, are used solely for informational or organizational purposes.

What is ExifTool?

The specifics of what meta tags are available and how they are encoded within a file varies based on file format. For instance, many image formats can include metadata about the camera used to capture it and its configuration (e.g. model, focal length, aperture, ISO, etc.). However, the way these tags are stored can vary between different image formats; a JPEG image uses EXIF (Exchangeable Image File Format) to store this metadata whereas a PNG image uses XMP (Extensible Metadata Platform).

ExifTool is a cross-platform command-line application for reading and editing metadata across various file formats. It acts as an abstraction layer over the specific metadata encoding used by any particular format, allowing the user to read and write metatags using a standard interface.

The following sections will explore how to use ExifTool to perform basic operations as well as some practical use-cases. To try these examples out yourself, first install ExifTool on your machine. Follow the official installation guidefor your platform or, on macOS, install using Homebrew: brew install exiftool.

Basic Usage

Read Specific Tags

With a file selected, invoke ExifTool with the filepath and the names of the meta tags to read. For instance, to read the width and height from screenshot.png in the current directory, you would run:

exiftool screenshot.png -ImageWidth -ImageHeight
exiftool screenshot.png -ImageWidth -ImageHeight

This command will print the value of each meta tag requested:

Image Width : 3302
Image Height : 2334
Image Width : 3302
Image Height : 2334

The ExifTool documentation includes an extensive list of available tag names and their possible values. Though ImageWidth and ImageHeight can be used on images consistently regardless of their format, other tags are specific to an individual format.

Read All Tags

Run ExifTool providing a file path as the only argument: exiftool <filepath>. This command will read all the meta tags present in the file as well as extra tags, metadata not present in the file itself such as file permissions.

Write or Remove Specific Tags

ExifTool also allows users to write new metadata to files or remove existing tags. This can be useful for updating information or clearing out unnecessary data. To write a specific tag, use the -TAG=VALUE syntax. For example, to add an author name to a file:

exiftool document.pdf -Author="John Doe"
exiftool document.pdf -Author="John Doe"

This command writes the Author tag with the value “John Doe” to document.pdf. To remove a specific tag, you can set its value to an empty string or use the -TAG= syntax without a value. For instance, to remove the Author tag:

exiftool document.pdf -Author=
exiftool document.pdf -Author=

Useful Applications

1. Organizing Photos by Event and Location

ExifTool can read metadata such as the date and GPS coordinates, allowing you to sort photos into folders based on events or places. For example, you can use the following command to copy photos into folders named after the city where they were taken:

exiftool '-Directory<${City}' -r /path/to/photo/directory
exiftool '-Directory<${City}' -r /path/to/photo/directory

This command recursively processes all photos in the specified directory, reading the City tag (if available) and moving each photo into a corresponding folder.

2. Adding Copyright and Usage Information

Those publishing their creative works online may want to add copyright and usage information directly in the file's metadata. This can be done using ExifTool to write specific tags like Copyright and UsageTerms:

exiftool -Copyright="© 2021 Your Name" -UsageTerms="All rights reserved" *.jpg
exiftool -Copyright="© 2021 Your Name" -UsageTerms="All rights reserved" *.jpg

This command adds copyright information and usage terms to all JPEG files in the current directory, making it clear under what terms the photos can be used.

3. Removing Sensitive Information from Files

ExifTool is also helpful for removing sensitive or personal information from files before sharing them. For instance, if you've taken photos with a smartphone, they might contain GPS coordinates that reveal your location. To remove this data:

exiftool -gps:all= -xmp:Location= -overwrite_original *.jpg
exiftool -gps:all= -xmp:Location= -overwrite_original *.jpg

This command removes all GPS data and location tags from the JPEG files, helping to maintain privacy when sharing photos online.

4. Embedding Keywords for Better Searchability

Adding keywords to the metadata of your files can greatly improve their searchability and organization. For example, adding descriptive keywords to photos can make it easier to find specific images later:

exiftool -Keywords="train, rail, track" station.jpg
exiftool -Keywords="train, rail, track" station.jpg

This command adds the keywords "train," "rail," and "track" to station.jpg, making it easier to search for this image using any of these terms.

5. Correcting Timestamps for File Synchronization

When dealing with multiple cameras or devices, timestamps can sometimes be incorrect or inconsistent due to varying time settings. ExifTool can correct these discrepancies by adjusting the timestamp metadata:

exiftool "-DateTimeOriginal+=1:0:0 0" -r /path/to/photos
exiftool "-DateTimeOriginal+=1:0:0 0" -r /path/to/photos

This command adjusts the DateTimeOriginal tag for all photos in the specified directory, adding one hour to each timestamp. This can be crucial for ensuring that photos from multiple sources appear in the correct chronological order.

Next Steps

This article has only scratched the surface of what is possible with ExifTool. To go further with ExifTool, start by consulting the official resources and the ExifTool Tag Names for detailed guides on metadata tags and command options.