How to Install and Use Exiftool on Linux

exiftool install linuxYou may have come across ExifTool while searching for an image recovery software. Well, ExifTool does more than that. It's a 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.

By the end of this article, we'll know how to install ExifTool on Ubuntu / CentOS and manipulate metadata of files. I'll be using CR2 (Canon raw files) format in this article, and that's perfectly fine. Modify the required parts of the commands used in this article to make your work.

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 libimage-exiftool-perl

From Source

You can compile and install ExifTool from the source on any Linux distro (including CentOS)

$ wget https://netix.dl.sourceforge.net/project/exiftool/Image-ExifTool-10.61.tar.gz
$ tar xvf Image-ExifTool-10.61.tar.gz
$ cd Image-ExifTool-10.61/

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.

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

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.

About Eyram Amedzor

Kwaku Eyram has been a working with computers and software for more than 10 years. He's an all-round geek and very fluid with Linux, Android and Windows operating systems. Asides being a tech enthusiast, Kwaku doubles as a tech support personnel and a tech writer. He currently has interest in IoT, web development and information security.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.