Utilities

Extracting Metadata of a File using ExifTool

ExifTool is a free and open source software program which is used to read, write and update metadata of various types of files such as PDF, Audio, Video and images. It is platform independent, available as a perl library as well as a command line application. Metadata can be described as information about the data such as file size, date created, file type, etc. ExifTool is very easy to use and gives a lot of information about the data. In this blog we will discuss different ways in which ExifTool can be used.

Installing ExifTool

It is quite easy to install ExifTool on Linux Machine. It can be installed by typing the following command in the terminal

ubuntu@ubuntu:~$ sudo apt-get install libimage-exiftool-perl

Now ExifTool is installed in your machine and is ready to use.

Extracting Entire Metadata of File

We can get entire metadata of a file by using the following command in the terminal

ubuntu@ubuntu:~$ exiftool <file_name>

When we type above command, we get all the information about file as shown below

It gives us a bunch of information about the file. In the above image all the details are not shown. You can see further details by scrolling down the terminal window.

We can use ExifTool with some options to extract specific data of the file. To see all the available options, type following command in the terminal.

ubuntu@ubuntu:~$ man exiftool

It will open the manual page for ExifTool, as shown below and we can see all the available options in this manual page. Some of these options have been  discussed here.

Extracting Common Metadata

We can extract the most common metadata of a file by using <common> option along with Exiftool command. Type the following command in the terminal to display common metadata of file.

ubuntu@ubuntu:~$ exiftool -common <file_name>

It will give us general information of the file as shown in the following image.

Extracting Location of the Image

Modern smartphones and digital cameras save GPS coordinates of the location, where image is captured, in each photo. We can extract GPS coordinates of the image by executing the following command in the terminal

ubuntu@ubuntu:~$ exiftool <file_name> | grep GPS

It will give us GPS coordinates of the location where the image was captured.

Extracting Specific Metadata

We can also extract specific metadata of file by using different options. You can see all the options in the manual page. Type the following command to see specific metadata

ubunut@ubuntu:~$ exiftool -<option> <file_name>

It will give us specific information specified by <option> field. We can also use more than one option as shown in the following image.

Creating Thumbnail Image

Thumbnail images can be described as a preview of original image which is less in size as compared to the original image. It describes how the original image looks like and can be opened quickly.

We can create thumbnail images by typing following command in the terminal

ubuntu@ubuntu:~$ exiftool -ThumbnailImage <file_name> > thumb.jpg

This will save the thumbnail of original image as “thumb.jpg” and this thumbnail will be lesser in size as compared to original image

We can see that thumbnail has been created and the size of thumbnail is just 86 bytes while the original image is 3.8 MB in size.

Extracting Metadata using Keywords

We can also extract our required metadata using keywords. For example, if we want to display image width using ExifTool, we will use width keyword to search for it. Following is the syntax to use keywords along with ExifTool.

ubuntu@ubuntu:~$ exiftool -”*width*<file_name>

When we type above command, it will give us all the tags related to width as shown in the following image.

We can see that all the tags related to “width” keyword have been displayed. In this way we can use any keyword to search for its related tags.

Verbose Mode of ExifTool

Verbose mode of ExifTool gives us more details of the file as compared to normal mode. We can go to verbose mode by using <-v> option along with ExifTool. The syntax of verbose mode is as follows

ubuntu@ubuntu:~$ exiftool -v <file_name>

In verbose mode, ExifTool will give us more information about the file as shown in the following image

Updating Metadata of a File

ExifTool provides us with the power to update the metadata of a file but this power is limited as we can not update all the tags of metadata. We can update some tags. Following is the syntax to update metadata of file

ubuntu@ubuntu:~$ exiftool -<tag_name>=”New_tag” <file_name>

This will change the <tag_name> to “New_tag” as shown in the image below

In the above image, can see that “F Number” tag has been updated from 4.0 to 6.0 and a new image has been created with the suffix of “_original”. The “F Number” tag in “image.jpg_original” will remain 4.0.

Some <tag_name> can not be updated like “Light Value”. When we try to update this <tag_name>, it will not change and gives a warning message as shown in the following image

In the above image neither the <tag_name> has been updated nor a new image with “_original” suffix has been created.

Removing Metadata of File

So far we have updated metadata and extracted metadata of a file. We can also remove metadata of a file using ExifTool. Metadata of a file can be removed by typing following command in the Terminal

ubuntu@ubuntu:~$ exiftool -all= <file_name>

When we type above command in terminal, not all but some metadata is removed. Following image explains it effectively

When we type above command, the original image is restored and a new image with changed metadata is created. We can see that metadata of the image is reduced.

Extracting Metadata of PDF Files

ExifTool is used not only with images, it can also be used to extract metadata of PDF and Video files too. The syntax to get metadata of PDF and Video files is same as that of images. Following image shows the metadata of PDF file

Conclusion

ExifTool is a powerful tool used to extract metadata of a file. It is used not only on images but some other formats of files like PDF and mp4 etc. It enables us to update and remove metadata of files and gives a lot of information about files.

About the author

Usama Azad

Usama Azad

A security enthusiast who loves Terminal and Open Source. My area of expertise is Python, Linux (Debian), Bash, Penetration testing, and Firewalls. I’m born and raised in Wazirabad, Pakistan and currently doing Undergraduation from National University of Science and Technology (NUST). On Twitter i go by @UsamaAzad14