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 }
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'
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
Related Commands
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,
wslvieworexplorer.exe .is often used. - Headless: If you are on a server, use
cat,less, orvimto "open" text files.xdg-openwon't work.