Skip to content

open (xdg-open) Command Cheat Sheet

In the Linux terminal, opening a file with its default GUI application (like double-clicking it) is done using xdg-open. On macOS, the equivalent is open.

This guide covers xdg-open, the cross-desktop standard for Linux.


Synopsis

xdg-open { file | URL }
(On macOS: open { file | URL })


Basic Usage

Open a File

Opens image.png in your default image viewer (e.g., Eye of GNOME).

xdg-open image.png

Open a URL

Opens the default web browser (Firefox/Chrome).

xdg-open https://google.com

Open File Manager

Opens the current directory in your File Explorer (Nautilus, Dolphin, Thunar).

xdg-open .

Alternative: Shortcuts

To make life easier on Linux, add this alias to your ~/.bashrc:

alias open='xdg-open'
Now you can just type:
open file.pdf


Troubleshooting

"xdg-open: no method available"

This usually means you are in a headless environment (Server without GUI). xdg-open requires a desktop environment (GNOME, KDE, XFCE).

Check Default Association

To see what app handles .png:

xdg-mime query default image/png
# Output: org.gnome.eog.desktop

Set Default Association

To set gimp as the default for .png:

xdg-mime default gimp.desktop image/png

gnome-open / kde-open

Older, desktop-specific commands. xdg-open tries to use these internally.

openvt

This is a totally different Linux command. openvt starts a program on a new Virtual Terminal (VT).

sudo openvt -s /bin/bash


Notes

  • WSL: In Windows Subsystem for Linux, wslview or explorer.exe . is often used.
  • Headless: If you are on a server, use cat, less, or vim to "open" text files. xdg-open won't work.