How to Install and Use Exiftool on Linux

Written by: Linuxopsys   |   Last updated: June 14, 2023

You may have come across ExifTool while searching for image recovery software. Well, ExifTool does more than that. It's an open-source program for reading, modifying, and manipulating images, videos, audios, and PDF metadata. Metadata are the additional data added to multimedia files. For example, the metadata of photographs are the additional data like the name of the device, the resolution of the image, the location the image was taken at, the date of capture and modification and more.

ExifTool supports several metadata formats including EXIF, GPS, XMP, GeoTIFF, Photoshop IRB, ID3, FlashPix. Your camera writes EXIF (Exchangeable image file format) and we'll be focusing on images in this article, but note that ExifTool can be used to modify the metadata of any file. Also, if you need to quickly and safely copy, move, rename, extract previews or modify multiple images at once, ExifTool is what you need.

In this guide, we learn how to install ExifTool on Linux and manipulate metadata of files.

Installing ExifTool

In this section, we'll be installing ExifTool on Ubuntu and other Linux distributions.

On Ubuntu

You can install ExifTool on Ubuntu using the apt utility.

# sudo apt install exiftool

From Source

You can compile and install ExifTool from the source on any Linux distro (including CentOS Stream). Download the latest version from ExifTool package home page.

$ wget https://exiftool.org/Image-ExifTool-12.50.tar.gz
$ tar xvf Image-ExifTool-12.50.tar.gz
$ cd Image-ExifTool-12.50/

You can run ExifTool by running ./exiftool in the ExifTool directory or proceed to the next step if you want to install it system-wide. You must have Perl installed on your Linux box before compiling.

# perl Makefile.PL
# make
# make test
# make install

You can now run ExifTool anywhere in your terminal by typing exiftool.

To check ExifTool version, type:

$ exiftool -ver
12.50

As of writing this guide, we have installed Exiftool 12.50 version.

You may also install it by cloning the ExifTool from GitHub.

git clone https://github.com/exiftool/exiftool.git
cd exiftool
./exiftool

Using ExifTool with Metadata

Here are the most common commands you can use with ExifTool:

Showing all the metadata associated with an image

$ exiftool IMG.CR2
 ExifTool Version Number : 10.61
 File Name : IMG.CR2
 Directory : .
 File Size : 16 MB
 File Modification Date/Time : 2017:09:24 12:15:41+00:00
 File Access Date/Time : 2017:09:24 12:16:16+00:00
 File Inode Change Date/Time : 2017:09:24 12:16:10+00:00
 File Permissions : rw-rw-r--
 File Type : CR2
 File Type Extension : cr2
 MIME Type : image/x-canon-cr2

In this example, we run exiftool against an image named "IMG.CR2" and we got a friendly metadata ranging from file Modification date, Image Width and Height, Color components to Megapixels.

If you want the same metadata, but instead of using readable metadata names like "Modify Date", you want the names you need to use when you'll use in actual ExifTool commands, use the -s options.  So instead of "File Name" you see "FileName", etc.

$ exiftool -s IMG.CR2
 ExifToolVersion : 10.61
 FileName : IMG.CR2
 Directory : .
 FileSize : 16 MB
 FileModifyDate : 2017:09:24 12:15:41+00:00
 FileAccessDate : 2017:09:24 12:16:16+00:00
 FileInodeChangeDate : 2017:09:24 12:16:10+00:00
 FilePermissions : rw-rw-r--
 FileType : CR2
 FileTypeExtension : cr2
 MIMEType : image/x-canon-cr2

Viewing Specific Metadata Properties of a File

Instead of using the previous command to view all the metadata, you can specify metadata property name before the image name to see the exact data. In this example, we'll extract the data for RedBalance, FileType, ShootingMode, and HDR for an image.

$ exiftool -RedBalance IMG_9110.CR2
 Red Balance : 1.495117

$ exiftool -FileType IMG_9110.CR2
 File Type : CR2

$ exiftool -ShootingMode IMG_9110.CR2
 Shooting Mode : Manual

$ exiftool -HDR IMG_9110.CR2
 HDR : Off

Extracting the Preview Image Embedded in Raw Files

Just in case you have a corrupted image, you can attempt extracting preview image or even the thumbnail using this command:

exiftool -b -PreviewImage IMG.CR2 > extract.jpg

The -b option tells exiftool to output data in binary format and extract.jpg is the destination file of the new image created. You can replace -PreviewImage with -ThumbnailImage if you want a thumbnail instead.

Moving or Copying Image Files into Folders by Year and Month

If you have several images you want to move them into new directories by year, month, or even days, you can easily get this done using exiftool in the example below:

$ exiftool -o '-Directory<CreateDate' -d ./NewImages/%y/%y%m -r ./OldImages
 4 directories scanned
 1 directories created
 9 image files updated
 4 image files unchanged

The example above copies the old images into new folders based on their year and month. The various parameters are explained below.

-o copies all the files and leave the source files in place. Removing this option will move them instead of copying them

-Directory<CreateDate moves the images to their new destination folders using the image creation date

./NewImages/%y/%y%m is the relative path to the folders the images to be copied to with the subfolders named after the year and then yearmonth.

-r repeats the process recursively over the source folder and it's subfolders.

./OldImages is the source folder where the entire operation begins from and the original images are kept.

We'll use the tree command to see the folder structure of the new arrangement of the images we manipulated. We can see the images are moved into a new folder with the year and then yearmonth subfolders.

$ tree
 .
 └── 17
     └── 1708
         ├── IMG_9110.CR2
         ├── IMG_9111.CR2
         ├── IMG_9112.CR2
         ├── IMG_9114.CR2
         ├── IMG_9115.CR2
         ├── IMG_9116.CR2
         ├── IMG_9117.CR2
         └── IMG_9118.CR2

2 directories, 8 files

Renaming Image Files According to their Creation Date

The following command renames all "CR2" (Canon) raw files, in current folder and its subfolders, according to the metadata Create Date and Time.

exiftool '-filename<CreateDate' -d %y%m%d_%H%M%S%%-c.%%e -r -ext CR2 ./RenamedImages

-filename<CreateDate tells exiftool to rename the images files using their creation data and time

-d means sets the format for data/time values

%y%m%d_%H%M%S%%-c.%%le is used to specify the format to use when renaming the file:
%y%m%d_ means the first part of the new file name will be last two digits of the creation year, month and date. The _ puts an underscore before the second part of the filename. %H%M%S adds the hour, minute, and second of the creation time.

%%-c adds an incremental copy number if multiple images have the name up to the point of the renaming process. -c just puts a dash before the copy number.

.%%e keeps the original file name extension.  If you want your extensions as lowercase or uppercase, use .%%le or .%%ue respectively.

-ext CR2 tells exiftool to rename files with only the CR2 extension. To rename all image files in the source folder, don't specify any extensions.

-r repeats the process recursively over the source folder and it's subfolders.

./RenamedImages is the relative path to the folder holding all your images to be renamed.

We'll use the tree command again to compare our original file names in OldImages to the new ones in RenamedImages.

.
├── Images
│       └── OldImages
│          ├── IMG_9110.CR2
│           ├── IMG_9111.CR2
│           ├── IMG_9112.CR2
│           ├── IMG_9114.CR2
│           ├── IMG_9115.CR2
│           ├── IMG_9116.CR2
│           ├── IMG_9117.CR2
│           └── IMG_9118.CR2
└── RenamedImages
├── 170827_184715.CR2
├── 170827_184726.CR2
├── 170827_184736.CR2
├── 170827_184800.CR2
├── 170827_184821.CR2
├── 170827_184848.CR2
├── 170827_184853.CR2
└── 170827_184855.CR2

Options

Let's check some useful exiftool options:

OptionsDescription
defaultDisplay all metadata from a file 
-sDisplay metadata in unfriendly names
-GDisplay metadata Group to which the metadata tag belongs.
-arg Format metadata as exiftool arguments
-b Display metadata in binary format
-d FMTSet format for date/time values
-DDisplay tag ID numbers in decimal
-p FMTFILEDisplay output in a specified format
-s[NUM]Reduce the output format
-rRecursively for every files directory and its subdirectories
-wwrite output to separate file
-extSpecify the file extension
-langDisplay supported language and helps to translate tags
-all:all= -r /path/to/directory/Remove all metadata from files recursively

Conclusion

ExifTool is a very powerful tool for manipulating file metadata. There are several applications and as expected, we couldn't add all the options. What did we miss? Tell us in the comments section now.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment