Useful ExifTool commands

2015-12-23 (last modified 2022-03-25) | Martin Hoppenheit | 3 min read

When editing metadata of single image files I usually use my graphical metadata editor Verso. But when it comes to working with lots of files en masse, like shifting the date of all images in a directory by two hours, nothing beats the command line. ExifTool is great for this. Here is a random collection of handy commands.

Modifying multiple tags simultaneously

Set the XMP Creator and Rights tags of all files in the current directory to the same value with one single command.

$ exiftool -XMP-dc:{Creator,Rights}='Martin Hoppenheit' .

Copying one tag to another

Copy the EXIF date/time of all files in the current directory to their respective XMP Date tag with the < operator.

$ exiftool '-XMP-dc:Date<DateTimeOriginal' .

Editing tags with regular expressions

Modify the XMP Description tag of all files in the current directory using Perl regular expressions. This works by copying the tag to itself and modifying the content on the way.

$ exiftool '-XMP-dc:Description<${XMP-dc:Description;s/foo/bar/g}' .

Searching in tags

List all files in the current directory which contain the strings ‘Laura’ or ‘Martin’ in their XMP Description tag, or all files that were made with a specific camera model. You can use pattern matching with regular expressions or any other kind of Perl logic expression.

$ exiftool -if '$XMP-dc:Description =~ /(Laura|Martin)/' -FileName -T .
$ exiftool -if '$Make eq "Jolla"' -FileName -T .

Shifting date/time values

Increment the EXIF date/time of all files in the current directory by six hours.

$ exiftool -DateTimeOriginal+=6 .

Renaming files based on tags

Rename all files in the current directory based on their XMP date. This works by copying the value of the XMP Date tag to the special FileName tag with the < operator. The -d option specifies the date format (which in this case effectively is the file name format), the %%-.2c pattern adds a file counter with minimum width 2 to all files with the same XMP date, the %%e pattern symbolizes the original file name extension.

$ exiftool '-FileName<XMP-dc:Date' -d %Y%m%d-%H%M%S%%-.2c.%%e .

Printing all metadata

Print all metadata of all files in the current directory. Include duplicate (-a) and unknown, even binary tags (-U).

$ exiftool -a -U .

Extension: Print tag names instead of descriptions like “ColorSpace” instead of “Color Space” (-s). Don’t print so-called composite tags which do not really exist in a file but are derived from “real” tags (-e). Prefix all tags with their general and specific location group like XMP:XMP-dc or EXIF:IFD0, thus also highlighting duplicate tags in different locations (-G0:1).

$ exiftool -a -U -s -e -G0:1 .

Deleting all metadata

Delete all metadata (or only the XMP metadata) of all files in the current directory.

$ exiftool -all= .
$ exiftool -XMP:all= .

Note that this is not always reliable, at least not for PDF files. From the ExifTool documentation on PDF metadata:

All metadata edits are reversible. While this would normally be considered an advantage, it is a potential security problem because old information is never actually deleted from the file.

File format validation

Look for errors that violate the file format specification (mainly JPEG and TIFF).

$ exiftool -validate -warning -error -a .

Custom output formatting

Apply a format string with the -p option. Compare the following default output in the first with the customized output in the second example. This is particularly useful for piping to the sort command or similar things.

$ exiftool -DateTimeOriginal -FileName .
======== ./foo.jpg
Date/Time Original  : 2013:12:12 14:20:39
File Name           : foo.jpg

$ exiftool -p '$DateTimeOriginal - $FileName' .
2013-12-12 14:20:39 - foo.jpg