Linux: remove EXIF data from photos using the command line

Photos - 2 tools for deleting EXIF data under Linux

This tutorial is about EXIF data in images, as I'm going to explain how to remove EXIF data from images using the Linux command line.

Most images contain EXIF data, which provides important - and sometimes unwanted - information, such as the time and date the picture was taken, the type of camera used and, in some cases, geolocation information. It is thanks to this data, which is used by certain software programs, that a smartphone is able to determine the location of a photo: not by analyzing the content of the image.

While EXIF metadata can be useful in a variety of scenarios, it's a threat to privacy! Personally, I think it makes sense to get rid of it.

Note EXIF stands for Exchangeable Image File Format.

1. Method 1: ExifTool

Let's start by looking at an initial method for removing EXIF data from one or more images. You should be aware that deleting this metadata also serves to reduce the image's weight.

ExifTool must be installed first.

# For Debian and Ubuntu :
sudo apt install libimage-exiftool-perl
# For Rocky Linux / CentOS / RHEL :
sudo dnf install perl-Image-ExifTool
# For Arch Linux :
sudo pacman -S perl-image-exiftool

ExifTool is used to manipulate the metadata linked to an image: both to display this data and to delete it. To list all the details of an image, you need to use the given command syntax:

exiftool

The result below shows that the " IMG20220809104055.jpg "It contains a wealth of EXIF metadata. For example, we can see the camera model, here corresponding to a smartphone.

Image Exif data

How do I remove metadata from an image?

There's a difference between image metadata and EXIF data. Metadata includes details such as file creator, file purpose, comments and so on. EXIF data, on the other hand, only includes details about the image itself, such as size, geographical location, exposure, camera, etc. Deleting an image's metadata also deletes its EXIF data.

To delete metadata, use the "-all" option. This will create a copy of the image without metadata, and the original file will be renamed with "_original" added to the end of the file.

exiftool -all=

If you look at the metadata of the image already taken as an example above, you can see that some clean-up has been done!

Linux - Remove EXIF data from an image with ExifTool.

Without compression, the difference in image weight is very slight indeed. With compression, we can change all that.

To delete only the EXIF data without affecting the metadata, replace the "-all" option with another option. Here's an example:

exiftool -EXIF=

Please note that if you wish to remove metadata from an image without creating a copy of the original with the suffix "_original" in the name, you can use this syntax :

exiftool -overwrite_original -all=

How do I delete image metadata from an entire directory?

Imagine a directory with dozens, hundreds or thousands of JPG images. Would you like to remove the EXIF data from all these images? It's possible! You need to use the -recurse option, which will ask ExifTool to browse the sub-directories.

exiftool -recurse -all=

To delete EXIF data from all images under " /home/tutobox/photos" we use :

exiftool -recurse -all= /home/tutobox/photos

2. Method 2: ImageMagick

Under Linux, there are various tools for manipulating EXIF data. Here, I'd like to show you how to do it with ImageMagick, another popular tool. Unlike the ExifTool, which was created to remove metadata and EXIF data, ImageMagick is a more comprehensive and versatile tool, as it is not designed solely to perform this operation. ImageMagick comes with a set of commands.

If you're used to using ImageMagick, you'll be pleased to know that it can also delete EXIF data. This will save you having to install another package on your server.

Let's move on to the installation of ImageMagick under Linux.

# For Debian and Ubuntu :
sudo apt-get install imagemagick
# For Rocky Linux / CentOS / RHEL :
sudo dnf install imagemagick
# For Arch Linux :
sudo pacman -S imagemagick

Once you've completed the installation, let's take a look at how you can list image details using the ImageMagick tool.

To list an image's EXIF data, use the following syntax to filter on information tagged with the "EXIF:" prefix:

identify -format '%[EXIF:*]'

I find the result less well presented than with the previous tool.

ImageMagick tool for listing image exif data

For delete EXIF data of the photo, you need to use the -strip with mogrify as shown below:

mogrify -strip

If we run this command and try to display the EXIF data, this time the result is empty, as there is no EXIF data left from our image stored on the Linux machine.

ImageMagick - Deleting EXIF data

You can also use this command on an entire directory. Unlike the first method, you cannot specify the path to the target directory. Here, it must be your current directory (you'll have to move around with "cd"). The result is :

mogrify -strip *

3. Conclusion

After reading this article, you will be able todisplay and delete EXIF data from your images from the Linux command line, with both ExifTool and ImageMagick.

Resources :

You may also like...

Leave a Reply

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