Open Files and URLs from the Terminal with xdg-open
Launch any file or link in its default application — the desktop-agnostic equivalent of macOS's open command.
Run xdg-open ~/report.pdf to open a PDF in the default viewer, xdg-open . to open the current folder in the file manager, or xdg-open https://github.com for the browser.
01Command
Command
$ xdg-open ~/report.pdf
xdg-open https://github.com
xdg-open .02What it does
xdg-open consults the desktop environment's MIME database and picks the same app double-clicking would use, working under GNOME, KDE, XFCE, and even WSL with some setup. It's the portable way to make shell scripts hand off to the GUI: an error report can end with xdg-open report.html and pop up in a browser. Directories open in the file manager, so xdg-open . is a quick 'show me this folder'.
03Risk
!Warning: On a headless server (no DISPLAY/WAYLAND_SESSION) xdg-open fails or misbehaves — it needs a running desktop session on the machine you invoke it from.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- xdg-open(1) — Linux man pageEvidence: xdg-open man page: 'opens a file or URL in the user's preferred application' noting it works for files, directories and http(s) URLs.
Last verified: 2026-09-17 · Category: Developer