Enhancing Ranger with exiftool: Advanced Image Metadata Viewing
Table of Contents 📑
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
Date | Change |
---|---|
2025-07-18 | Initial 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
class exif_info(Command):
"""
:exif_info
Shows file metadata using exiftool
"""
def execute(self):
# Get the path of the currently selected file
filename = self.fm.thisfile.path
# Run exiftool on the selected file - it will handle unsupported files gracefully
# The single quotes around '{filename}' are crucial for handling
# filenames with spaces or special characters
self.fm.execute_command(f"exiftool '{filename}' | less")
This command will:
- Check if the selected file has a supported extension
- Run
exiftool
on the file and pipe the output toless
for easy viewing - Display a notification if the file type is not supported
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 ei
(which stands for “exif info”):
map ei exif_info
This shortcut is easy to remember as ei
stands for “exif info” - which is exactly what this command does: it shows you detailed metadata information about your files.
Shortcut | Description |
---|---|
ei | Show 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 works with any file type that exiftool can process. There’s no need to modify the code to support new file types - exiftool will automatically handle:
- 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.)
If exiftool doesn’t support a particular file type, it will simply display an appropriate message.
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:
self.fm.execute_command(f"exiftool -DateTimeOriginal -Make -Model -LensModel -ExposureTime -FNumber -ISO '{filename}' | 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:
self.fm.execute_command(f"exiftool '{filename}' | bat --style=plain --color=always | less -R")
5. Usage
Once everything is set up, you can use your new metadata viewing capability:
- Open ranger in your terminal
- Navigate to an image or media file
- Press your configured shortcut (e.g.,
ei
) - Browse through the metadata information
- 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:
- Use
zi
(if you have the fzf integration) to quickly find images - Use
ei
to check their metadata - 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.
Related Ranger Guides
Enhance your ranger experience with these additional tutorials:
- Ranger and fzf Integration - Add powerful fuzzy search capabilities
- File Compression Workflow - Create and extract archives easily
- Advanced Media Preview Configuration - Customize file previews for various formats
- Ranger and sxiv Integration - Create a seamless image viewing workflow