xdg-open
Open file or URL with default application
TLDR
Open the current directory in the default file explorer
Open a URL in the default browser
Open an image in the default image viewer
Open a PDF in the default PDF viewer
Display help
SYNOPSIS
xdg-open [OPTIONS] FILE | URL
PARAMETERS
--help
Display a help message and exit.
--version
Show version information and exit.
--verbose
Enable verbose output, providing more details about the command's execution.
--debug
Enable debug output, which is even more detailed than verbose, useful for troubleshooting.
DESCRIPTION
The xdg-open command is a utility designed to open files, URLs, or directories using the user's preferred application, as defined by their desktop environment. It is part of the xdg-utils package, which provides a set of common desktop integration utilities across different Linux desktop environments like GNOME, KDE, XFCE, and LXQt.
Rather than requiring users or applications to know the specific commands for each desktop environment (e.g., gvfs-open for GNOME, kde-open for KDE), xdg-open offers a standardized and desktop-agnostic interface. It intelligently determines the appropriate application by inspecting the MIME type of the file or URL, consulting system-wide and user-specific MIME type associations. This ensures a consistent user experience, allowing scripts and applications to open content seamlessly without needing to detect the active desktop environment. For example, opening a PDF will launch the default PDF viewer, while a web URL will open in the default web browser.
CAVEATS
xdg-open relies heavily on a properly configured desktop environment and MIME type associations. If MIME types are incorrectly set, or if no default application is registered for a specific file type, the command may fail or open the content with an unexpected application. It also requires a running X server or Wayland compositor for graphical applications to launch successfully. In a headless environment (without a graphical display), it will only be able to open non-graphical content or URLs that can be handled by command-line tools (e.g., a text file in a terminal editor, if configured).
MIME TYPE HANDLING
xdg-open's core functionality is built upon the XDG Desktop Specification for MIME type handling. When invoked with a file or URL, it identifies its MIME type and then looks up the preferred application registered for that type. This registration is typically done via .desktop files and user-specific configurations in ~/.config/mimeapps.list, ensuring that the user's choices for default applications are respected.
HISTORY
The xdg-open command is a key component of the xdg-utils package, which was developed under the Freedesktop.org initiative. Freedesktop.org aims to standardize core desktop components and specifications across various Linux and Unix-like desktop environments. xdg-open was created to address the long-standing problem of application launching consistency. Before its existence, applications often had to use environment-specific commands to open files or URLs, leading to fragmented and non-portable scripts. Its development allowed for a unified API for opening resources, greatly simplifying application development and improving user experience across diverse desktop setups.
SEE ALSO
xdg-email(1), xdg-mime(1), xdg-settings(1), gvfs-open(1), mimeopen(1)