1. Introduction

Image files and other file formats can contain metadata also known as Exchangeable Image File Format (EXIF) data. It helps to find potentially useful information about an image, such as creation date, pixel format, and others.

In this tutorial, we’ll learn how to read and modify EXIF data for an image.

2. The exiftool Command

The utility we’ll be using throughout is the exiftool command. exiftool is a popular and free open-source tool for accessing and modifying EXIF metadata.

Some Linux distributions don’t have exiftool by default, so we may need to install it using the apt-get command:

$ sudo apt-get install exiftool

As a result, we should be able to run the exiftool command and see no errors:

$ exiftool
Syntax:  exiftool [OPTIONS] FILE
Consult the exiftool documentation for a full list of options.

Now, we’re ready to run exiftool commands on our Linux machine.

3. Read EXIF Data

First, let’s see how to read and output EXIF data of a sample image called test.jpg.

3.1. Print All EXIF Fields

To print all EXIF data of an image, we specify the image name as the argument to exiftool:

$ exiftool test.jpg
ExifTool Version Number         : 12.40
File Name                       : test.jpg
Directory                       : .
File Size                       : 15 KiB
File Modification Date/Time     : 2023:05:21 10:18:43+03:00
File Access Date/Time           : 2023:05:21 10:18:43+03:00
File Inode Change Date/Time     : 2023:05:21 10:18:43+03:00
File Permissions                : -rw-r--r--
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Exif Byte Order                 : Big-endian (Motorola, MM)
X Resolution                    : 100
Y Resolution                    : 100
Resolution Unit                 : inches
Y Cb Cr Positioning             : Centered
Exif Version                    : 0232
Date/Time Original              : 2023:05:18 11:23:55
Components Configuration        : Y, Cb, Cr, -
Flashpix Version                : 0100
Color Space                     : Uncalibrated
Image Width                     : 1280
Image Height                    : 720
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 1280x720
Megapixels                      : 0.922

We can see all EXIF field (tag) metadata of the test.jpg image.

For example, the File Name field provides the name of our image. The Date/Time Original field shows the time when the image was created. We can also see the Exif Version, resolution as Image Width and Image Height, as well as other potentially useful data.

3.2. Read Specific EXIF Field

To read a specific EXIF field, we provide the compressed field’s name after a dash. We can use both flat case and camel case for it.

For example, let’s print the File Name field:

$ exiftool -FileName test.jpg
File Name                       : test.jpg

By using -FileName, we only print the File Name field.

Likewise, to print multiple fields, we can specify each of them in a single command:

$ exiftool -FileName -ExifVersion test.jpg
File Name                       : test.jpg
Exif Version                    : 0232

The field or tag names are mostly the same as their output names, barring any whitespace and other special characters.

4. Modify the EXIF Field

To modify an EXIF field, we can use the key=value syntax:

exiftool -<fieldName>=<new value> test.jpg

The <new value> is the value to be assigned to the specified field by <fieldName>.

Let’s look at how we can modify EXIF fields.

4.1. Assign New Value

To assign a new value to a field, we can use a basic command:

$ exiftool -FileModifyDate="2023:05:20 07:23:05+01:00" test.jpg
    1 image files updated

Thus, we’ve just written the new value to the FileModifyDate field.

Furthermore, we can check that it’s been assigned correctly by reading back the FileModifyDate field:

$ exiftool -FileModifyDate test.jpg
File Modification Date/Time     : 2023:05:20 07:23:05+01:00

As expected, the field value now has the new date.

4.2. Copy Field Value

Sometimes, we may need to have several fields with the same values. For such a situation, we can use the copy operator >:

$ exiftool "-DateTimeOriginal>FileModifyDate" test.jpg
    1 image files updated

In this case, we copied the DateTimeOriginal field value to the FileModifyDate field. The quotation marks are obligatory in this command.

Finally, to check that both fields now have the same values, let’s read them:

$ exiftool -DateTimeOriginal -FileModifyDate test.jpg
Date/Time Original              : 2023:05:18 11:23:55+01:00
File Modification Date/Time     : 2023:05:18 11:23:55+01:00

Indeed, we can see that the DateTimeOriginal and the FileModifyDate fields are identical.

5. Conclusion

In this article, we learned how to use and interact with the EXIF metadata of a file using the exiftool command. Firstly, we learned how to read EXIF values. After that, we looked at ways to modify them.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.