How to install and use ExifTool on Linux

You may come across ExifTool while looking for image recovery software. Well, ExifTool does more than that. It is open source and is designed to read, modify and manipulate images, video, audio and metadata in PDF format. Metadata is additional data added to multimedia files. For example, photo metadata is additional data such as device name, image resolution, location, date of capture and modification, and more.

ExifTool supports multiple metadata formats including EXIF, GPS, XMP, GeoTIFF, Photoshop IRB, ID3, FlashPix. The camera records EXIF ​​(Image File Format) and we will be focusing on images in this article, but note that ExifTool can be used to change the metadata of any file. Plus, if you need to quickly and safely copy, move, rename, extract previews, or modify multiple images at once, ExifTool is the way to go.

By the end of this article, we will know how to install ExifTool on Ubuntu / CentOS and manipulate file metadata. We’ll be using the CR2 format (Canon RAW files) in this article, which is good. Modify the required parts of the command used in this article to make this work.

Installing ExifTool

In this section, we will install ExifTool on Ubuntu and other Linux distributions

In 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 source on any Linux distribution (including CentOS)

$ wget
$ tar xvf Image-ExifTool-10.61.tar.gz
$ cd Image-ExifTool-10.61/

You can start ExifTool by running ./exiftoolin the ExifTool directory or go to the next step if you want to install it system wide. You must have Perl installed on your Linux machine before compiling.

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

You can now launch ExifTool in your terminal by entering exiftool

Using ExifTool

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

Shows all metadata associated with the image

$ exiftool IMG.CR2
 ExifTool Version Number : 10.61
 File Name : IMG.CR2
 Directory : .
 File Size : 16 MB
 File Modification Date/Time : 2017:09:28 11:10:33+00:00
 File Access Date/Time : 2017:09:28 11:17:17+00:00
 File Inode Change Date/Time : 2017:09:28 11:17:11+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 with an image called “IMG.CR2” and we got metadata starting with the modification file date, image width and height, color components and megapixels.

If you want the same metadata, but instead use machine-readable metadata names such as Modified Date, and you want the names you must use, then you need to use in actual ExifTool commands, use the option -s… So instead of “Filename” you see “FileName” and so on.

$ exiftool -s IMG.CR2
 ExifToolVersion : 10.61
 FileName : IMG.CR2
 Directory : .
 FileSize : 16 MB
 FileModifyDate : 2017:09:28 11:17:38+00:00
 FileAccessDate : 2017:09:28 11:17:17+00:00
 FileInodeChangeDate : 2017:09:28 11:17:11+00:00
 FilePermissions : rw-rw-r--
 FileType : CR2
 FileTypeExtension : cr2
 MIMEType : image/x-canon-cr2

View file properties metadata

Instead of using the previous command to view all metadata, you can prefix the metadata property name before the image name to see the exact data. In this example, we will be fetching data for RedBalance, FILETYPE, ShootingMode and HDR for an image.

$ exiftool -RedBalance IMG_0221.CR2
 Red Balance : 1.495117

$ exiftool -FileType IMG_0221.CR2
 File Type : CR2

$ exiftool -ShootingMode IMG_0221.CR2
 Shooting Mode : Manual

$ exiftool -HDR IMG_0221.CR2
 HDR : Off

Extracting a preview image embedded in raw files

Only in case you have a corrupted file can you try extracting a preview image or even a thumbnail using the following command:

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

The -b option tells ExifTool to output the data in binary format and extract.jpg is the destination file of the new image it creates. You can replace -PreviewImage on -ThumbnailImageif you want a thumbnail instead.

Move or copy image files to folders by year and month

If you have multiple images that you want to move to new directories, per year, month, or even days, you can easily do this using the 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 above example copies old images to new folders based on their year and month. The various options are described below.

  • -o copies all files and leaves the original files in place. Removing this option will move them instead of copying them
  • -Directory<CreateDate moves images to their new destination folders using the image creation date
  • ./NewImages/%y/%y%m the relative path to the image folders to be copied from the subfolders of the year name followed by yearMonth.
  • -r repeats the process recursively through the original folder and subfolders.
  • ./OldImages source folder where the whole operation starts and the original images are saved.

We will use the command treeto see the folder structure of the new image layout we were operating on. We can see the images moved to a new folder with year, and then to a subfolder yearMonth.

$ tree
 └── 17
     └── 1708
         ├── IMG_0221.CR2
         ├── IMG_0111.CR2
         ├── IMG_0112.CR2
         ├── IMG_0114.CR2
         ├── IMG_0115.CR2
         ├── IMG_0116.CR2
         ├── IMG_0117.CR2
         └── IMG_0112.CR2

2 directories, 8 files

Renaming image files according to their creation date

The following command renames all “CR2” (Canon) source files in the 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 image files using its data and creation time
  • -d means it sets the data format for time values
  • %y%m%d_%H%M%S%%-c.%%le used to define the format to use when renaming the file:% r% m% d_ means the first part of the new file name will be the last two digits of the creation year, month and day.
  • _ Places an underscore before the second part of the filename. %H%M%S adds hours, minutes and seconds of creation time.
  • %%-c adds an extra copy count if multiple images are named up to the point of the renaming process.
  • -c simply puts a dash in front of the copy number.
  • .%%e retains the original filename extension. If you want your extensions to be either lowercase or uppercase use .%%le or .%%ue respectively.
  • -ext CR2 tells ExifTool to rename files with CR2 extension only. To rename all image files in the original folder, do not specify any extensions.
  • -r repeats the process recursively through the original folder and subfolders.
  • ./RenamedImages the relative path to the folder where all your images will be renamed.

We will use the command tree again to compare our original filenames in OldImages for new in RenamedImages

, ├── Images │ └── OldImages │ ├── IMG_0221.CR2 │ ├── IMG_0111.CR2 │ ├── IMG_0112.CR2 │ ├── IMG_0114.CR2 │ ├── IMG_0115.CR2 │ ├116 IM_G … CR2 │ ├── IMG_0117.CR2 │ └── IMG_0112.CR2 └── RenamedImages ├── 112211_154715.CR2 ├── 112211_154726.CR2 ├── 112211_154736.CR2 ├── 112211_─154800.CR11.CR2 ── 112211_─154800.CR11 ── 112211_154848.CR2 ├── 112211_154853.CR2 └── 112211_154855.CR2

ExifTool is a very powerful tool for working with file metadata. There are several applications, as expected, we could not add all the options. What have we missed? Tell us in the comment section.