For photographers, designers, and anyone working with digital media, having quick access to file metadata is essential. This guide shows you how to integrate the powerful exiftool utility with the ranger file manager, allowing you to view comprehensive metadata for images and other media files without leaving your terminal.

Changelog

DateChange
2026-01-12Shortcut Update: Switched metadata shortcut from ei to ii (inspect/media prefix)
2025-07-18Initial Version: Created guide for integrating exiftool with ranger

1. Prerequisites

Before we begin, make sure you have the following tools installed:

  • ranger: The terminal file manager
  • exiftool: A powerful utility for reading, writing, and manipulating metadata

Installation on Various Distributions

# For Debian/Ubuntu
sudo apt update && sudo apt install ranger libimage-exiftool-perl

# For Arch Linux
sudo pacman -S ranger perl-image-exiftool

# For Fedora
sudo dnf install ranger perl-Image-ExifTool

2. Creating the Custom exif_info Command

The integration requires adding a custom command to ranger that will use exiftool to display metadata for the selected file.

2.1. Create or Edit commands.py

First, navigate to your ranger configuration directory and create or edit the commands.py file:

mkdir -p ~/.config/ranger
touch ~/.config/ranger/commands.py

If you don’t have a commands.py file yet, you can generate a template with:

ranger --copy-config=commands

2.2. Add the exif_info Command

Open the commands.py file in your favorite text editor and add the following code:

from ranger.api.commands import Command
import mimetypes
import os
import shlex
import shutil
import subprocess

class exif_info(Command):
    """
    :exif_info

    Shows file metadata using exiftool
    """
    def execute(self):
        f = self.fm.thisfile
        if not f:
            return

        filename = f.path
        if not filename or os.path.isdir(filename):
            return

        mime = None

        if shutil.which("file"):
            try:
                mime = subprocess.check_output(
                    ["file", "--mime-type", "-Lb", filename],
                    text=True,
                    stderr=subprocess.DEVNULL,
                ).strip()
            except Exception:
                mime = None

        if not mime:
            mime, _ = mimetypes.guess_type(filename)

        is_media = False
        if mime:
            is_media = (
                mime.startswith(("image/", "video/", "audio/"))
                or mime == "application/pdf"
            )

        if is_media:
            q = shlex.quote(filename)
            self.fm.execute_command(f"exiftool {q} | less")
        else:
            self.fm.display_file()

This command will:

  1. Detect whether the selected file is an image, video, audio file, or PDF (using file --mime-type when available, with an extension-based fallback)
  2. Run exiftool on media/PDF files and pipe the output to less for easy viewing
  3. Fall back to ranger’s default preview (display_file()) for all other file types

3. Creating a Keyboard Shortcut

Now that we have our custom command, let’s create a keyboard shortcut to invoke it easily.

3.1. Edit rc.conf

Open your ranger configuration file:

vim ~/.config/ranger/rc.conf

If you don’t have this file yet, you can generate it with:

ranger --copy-config=rc

3.2. Add the Keyboard Mapping

Add the following line to map the exif_info command to a keyboard shortcut. In this example, we’ll use ii (which stands for “inspect info”):

map ii exif_info

We use i as a generic inspect / media prefix to group all image and media-related actions and avoid conflicts with ranger’s built-in o (order) commands.

This shortcut is easy to remember as ii stands for “inspect info” - which is exactly what this command does: it shows you detailed metadata information about your files.

ShortcutDescription
iiShow detailed metadata for the selected file using exiftool

4. Advanced Configuration

4.1. Using with Different File Types

One of the advantages of this implementation is that it targets media-related formats and avoids running exiftool on unrelated file types. The command will automatically use exiftool for:

  • Common image formats (JPG, PNG, GIF, TIFF, etc.)
  • RAW camera formats (CR2, NEF, ARW, DNG, etc.)
  • Video files (MP4, MOV, AVI, MKV, etc.)
  • Document formats (PDF, etc.)
  • Audio files (MP3, FLAC, etc.)

For everything else, it will fall back to ranger’s normal file preview.

4.2. Format the Output

You can customize how the metadata is displayed by modifying the command that calls exiftool. For example, to show only specific tags:

q = shlex.quote(filename)
self.fm.execute_command(f"exiftool -DateTimeOriginal -Make -Model -LensModel -ExposureTime -FNumber -ISO {q} | less")

4.3. Create a Colorized Output

For a more visually appealing output, you can use bat instead of less if you have it installed:

q = shlex.quote(filename)
self.fm.execute_command(f"exiftool {q} | bat --style=plain --color=always | less -R")

5. Usage

Once everything is set up, you can use your new metadata viewing capability:

  1. Open ranger in your terminal
  2. Navigate to an image or media file
  3. Press your configured shortcut (e.g., ii)
  4. Browse through the metadata information
  5. Press q to exit the viewer and return to ranger

6. Practical Examples

6.1. Photography Workflow

For photographers, this integration is particularly useful for quickly checking:

  • Camera settings (aperture, shutter speed, ISO)
  • Lens information
  • Date and time the photo was taken
  • GPS coordinates (if available)
  • Copyright information

6.2. Batch Processing

You can combine this with other ranger commands to create a powerful workflow. For example, you could:

  1. Use zi (if you have the fzf integration) to quickly find images
  2. Use ii to check their metadata
  3. Use ranger’s tagging system to organize files based on metadata information

6.3. Checking File Integrity

For downloaded files or files received from others, you can quickly check:

  • Creation and modification dates
  • Software used to create the file
  • Embedded comments or descriptions
  • File integrity information

7. Troubleshooting

7.1. Command Not Found

If you get a “Command not found” error when trying to use the shortcut:

  • Make sure you’ve saved the commands.py file correctly
  • Restart ranger to load the new command
  • Check that exiftool is installed and in your PATH

7.2. No Metadata Displayed

If no metadata is displayed for a file:

  • The file might not contain any metadata
  • The file format might not be supported by exiftool
  • There might be permission issues with the file

Try running exiftool directly on the file to see if it works outside of ranger:

exiftool path/to/your/file

Summary

With this integration, you’ve enhanced ranger’s capabilities for working with digital media files:

✅ Quick access to comprehensive file metadata ✅ Support for a wide range of file formats ✅ Customizable keyboard shortcuts ✅ Seamless integration with your terminal workflow

This setup is particularly valuable for photographers, designers, and anyone who works with digital media files regularly. It combines the file management power of ranger with the detailed metadata analysis capabilities of exiftool.

📚EXIFTOOL DOCUMENTATION 🔧RANGER CUSTOM COMMANDS 🏷️EXIFTOOL TAG NAMES

Enhance your ranger experience with these additional tutorials: