How To Open Image Files In Linux Terminal

GUI has many tools for viewing and interacting with image files on Linux. However, a command line tool offers flexibility and efficiency, especially for tasks that need to be automated or performed remotely. In this tutorial, I will show you different ways to open image files using Linux command-line tools

The easiest and simplest method to view image files without using a desktop environment and X/Wayland is to use Framebuffer Image Viewer using the fbi command. Other options include the Image to ASCII conversion tools like the Terminal Image Viewer (tiv).

Whether you want to open images in a desktop environment, in a terminal with X/ Wayland, or console mode without any X Server running, this tutorial shall equip you with all the tools required to open Image files using the Linux command line tools.

Want the best experience? Become a premium member for ad-free browsing, access exclusive content, and ask questions in our private forums. Your membership helps support the site!
Linux doesn’t have to be intimidating. With my e-book, Master Linux Commands, you’ll uncover the secrets of the terminal in a fun, step-by-step journey. From basics to scripts, get ready to level up your Linux skills. Oh, and did I mention the handy cheat sheet you get as a bonus?

Overview of the different solutions

Linux command line tools offer a variety of options for opening Image files. However, there are different use case scenarios each option is tailored for. Generally, the most common use case scenarios can be divided into the following broad categories:

Note: The latest version of Debian 12 Bookworm (Debian 12.5.0) was used to test all methods mentioned in this tutorial.

Launching GUI Applications from Terminal

Most Linux distributions come with a desktop environment pre-installed. Each desktop environment comes packed with a built-in Image viewer. For example, the default image viewer for GNOME is the Eye of GNOME.

Following are a few GUI-based tools that can be used to preview images:

  • Eye of GNOME: Default Image Viewer for GNOME (Ubuntu/ Debian) and Mate.
  • Gwenview: Default Image Viewer for KDE-Plasma.
  • LXImage: Default Image Viewer for LXQT.
  • Simple X Viewer: A simple Lightweight image viewer. It can be installed from official repositories.
  • XDG-OPEN Tool: A tool that can universally be used to open images in the default image viewer.

Eye of GNOME (EOG)

To open an image in the Image Viewer on GNOME or Mate, open a Terminal and enter the following command:
eog <file name>

Doing so shall open the GUI application in which you can see the image:

Gwenview

To open an image in the Image Viewer in KDE-Plasma, open a Terminal and enter the following command:
gwenview [options] <file name>

Doing so shall open the GUI application in which you can see the image:

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

LXImage

To open an image in the Image Viewer in LXQT, open a Terminal and enter the following command:
lximage-qt <file name>

Doing so shall open the image in the GUI application:

Simple X Image Viewer (SXIV)

If you do not prefer the default Image Viewer that came with your distribution/ desktop environment or your desktop environment does not have one. You can use the Simple X Image Viewer (sxiv).

sxiv is a lightweight and scriptable Image Viewer written in C. It is available on the official repository and can be installed with the command:
sudo apt install sxiv

Now you can open the image files in sxiv using the command:
sxiv [OPTIONS] <file name>

This should open your required image file in sxiv:

sxiv can also be used to preview GIFs. To open a GIF enter the following command:
sxiv -A 10 <file name>

This shall show the GIF animated at 10 FPS:

If you’re new to the Linux command line, this article will give you the most important Linux commands to know, plus a free downloadable cheat sheet to keep handy.

XDG-OPEN Command

One convenient command line tool to open any image file in the terminal is the xdg-open tool. This tool comes pre-installed in most Linux distributions. It opens the required file or URL in the user’s preferred applications (set in the system preferences).

To open an image using the xdg-open tool enter the following command in the terminal:
xdg-open <file name>

X Forwarding Over SSH

If you are looking for a way to view images remotely the simplest option is X Forwarding over SSH. Through X Forwarding you can open any GUI application on your client PC as if it was running on the Server.

  • Linux and MacOS: These OS come pre-packed with an X-Server.
  • Windows 11: You need to install some X-Server if working on Windows.

Linux/ Mac OS

To X Forward over SSH to a Linux or MacOS Desktop follow these steps:

  • Open Terminal on your desktop.
  • Enter the following command in your terminal:
    For Linux:
    ssh -X username@hostname
    For macOS:
    ssh -Y username@hostname
  • Now you can use any application that requires X to display images on your desktop. For example, you can use the xdg-open tool:
    xdg-open <file name>
  • Alternatively, you can use sxiv:
    sxiv <file name>
  • This should open the image file in your application of choice:

Windows 11

To X Forward over SSH to a Windows 11 Desktop follow these steps:

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now
  • Install some X Server applications. You can try installing Xming from the official website. Alternatively, you can enter the following command in Windows Command Prompt:
    winget install Xming.Xming
  • Once installed, search for Xming in the start menu and run it.
  • Next, set the Display environment variable using the following command:
    setx DISPLAY localhost:0
  • Restart the Command Prompt.
  • Enter the following command to SSH:
    ssh -Y username@hostname
  • Now you can use any application that requires X to display images on your desktop in Xming. For example, you can use the xdg-open tool:
    xdg-open <file name>
  • Alternatively, you can use sxiv:
    sxiv <file name>
  • This should open the image file in your application of choice:

Opening Images in Terminal Using X

If you are looking for tools to view images in your Terminal without any fancy desktop environment/ window manager, the simplest method is to use feh. Alternatively, you can use the Ranger file browser with a built-in image preview option.

Although both of these methods work from the terminal, however, these require that you already have an X Server running as a desktop environment/ window manager or that the application is launched in Kiosk mode using the startx command.

FEH

feh is a minimal tool for viewing raster images in a Linux terminal. It is available in most official repositories and does not require any desktop environment/ window manager. It only uses the X Window System to display images.

To use feh follow these steps:

  • Update your system using the command:
    sudo apt-get update && sudo apt-get upgrade
  • Now you can install feh using the command:
    sudo apt install feh
  • You can use the following command to open an image file in feh:
    feh [OPTIONS] <file name>
  • This should open your image file in feh:
  • feh image viewer does not have any GUI buttons. You can use the right and left arrows to scroll through images and the up and down arrows to zoom in or out. Press ‘Q’ to exit.
  • You can see all options available in feh on the official Linux manual/ documentation.

Ranger File Browser

Another option to preview image files in a Linux terminal (without using any GUI) is the Ranger file browser. Ranger is a text-based file browser that runs in your terminal. It has the option to enable the preview of files including image files.

To use the Ranger file browser follow these steps:

  • Update your system using the command:
    sudo apt-get update && sudo apt-get upgrade
  • Install Ranger using the command:
    sudo apt install ranger
  • Generate the default configuration of Ranger using the command:
    ranger --copy-config=all
  • Edit the configuration file (rc.conf) using any suitable text editor:
    sudo nano ~/.config/ranger/rc.conf
  • Search for the line “set preview_images false” and set it to true:
  • Search for the line “set preview_images_method” and set it to the desired method (different methods are supported for previewing images, as of my testing w3m no longer works with Wayland, and therefore the recommended method is kitty):
  • Now you can execute the ranger browser by simply entering the following command:
    ranger
  • This should open a file browser in the terminal in your current working directory:
  • Navigate to the directory (using the left and right keys) containing your image files and hover over them to see a preview in the right pane.

Opening Images in Terminal Without X

If you are working on a server in console mode (without any desktop environment or X Server), you have the following options:

  • Frame Buffer Image Viewer (fbi): The simplest and most versatile method to preview images. It cannot be easily used over SSH.
  • Img2txt tool from caca-utils: This can be conveniently used over SSH. However, the preview quality is poor.
  • Terminal Image Viewer (tiv): Uses a methodology similar to the Img2txt tool. However, preview quality is significantly improved if the terminal supports RGB ANSI codes and Unicode block graphic characters.

Frame Buffer Image Viewer

Frame Buffer Image Viewer (fbi) is a lightweight tool. It comes pre-installed in most Linux distributions. It can preview images without any X Server or Desktop Environment. PhotoCD, JPEG, PPM, GIF, TIFF, XWD, BMP, and PNG are supported directly. For other formats, fbi tries to use ImageMagick’s convert.

If your Linux does not include fbi by default. You can install it using the following command:
sudo apt install fbi

To view an image using fbi enter the following command:
fbi [Options] <file name>

This will open the image:

You can use the Plus and Minus keys to zoom in and out. Press Q to exit. You can press H to see all available keyboard shortcuts.

The major limitation of this method is that it cannot be easily used to view images over SSH. It can only be used to view images locally.

CACA-UTILS (IMG2TXT)

Are you looking for a tool that can be used locally and over an SSH and does not require an X Server? The simplest method is to use img2txt tool. img2txt tool comes packed with the caca-utils (available in most official repositories) library in Linux. It supports PNG, JPEG, GIF, PNG, BMP formats.

To install caca-utils run the command:
sudo apt install caca-utils

Once installed you can use the img2txt command to preview images converted to ASCII:

The same method can be used to preview images over SSH as well:

This method has the advantage of being used over SSH. However, the quality of the image is significantly affected. You can only get a general idea of the image content.

Terminal Image Viewer (TIV)

Terminal Image Viewer (tiv) is a small C++ program that displays images using the RGB ANSI codes and Unicode block graphic characters. The source code of this application is being maintained on its Github page.

To use tiv follow these steps:

  • Clone the GitHub repository using the command:
    git clone https://github.com/stefanhaustein/TerminalImageViewer.git
  • change directory to the source code directory:
    cd TerminalImageViewer/src
  • Make installation files:
    make
  • Move tiv binaries to your Path:
    sudo make install
  • Make sure that ImageMagick is installed:
    sudo apt install imagemagick
  • Now you can view images using the following command:
    tiv [OPTIONS] <file name>
  • The same command can be used over SSH as well:

As you can see tiv uses a similar methodology as img2txt, however, the previewed image is of much better quality when used over SSH (depending upon the terminal).

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

Conclusion

As you can see there is no shortage of methods to view image files in a Linux terminal. If you are looking for a simple method to view images locally without using any X Server, Frame Buffer Image Viewer (fbi) is recommended.

However, if you are looking for a versatile option that can be used to display images locally as well as remotely over SSH. then Terminal Image Viewer (tiv) may be used.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Want to chat with other Raspberry Pi enthusiasts? Join the community, share your current projects and ask for help directly in the forums.

Additional Resources

Overwhelmed with Linux commands?
My e-book, “Master Linux Commands”, is your essential guide to mastering the terminal. Get practical tips, real-world examples, and a bonus cheat sheet to keep by your side.
Grab your copy now.

VIP Community
If you just want to hang out with me and other Linux fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.

Need help building something with Python?
Python is a great language to get started with programming on any Linux computer.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.

Similar Posts