open
Open a file or directory in macOS
TLDR
View documentation for the command available in macOS
View documentation for the command available through fish
SYNOPSIS
xdg-open [options] {file | URL}
xdg-open --help
xdg-open --manual
xdg-open --version
xdg-open --dry-run {file | URL}
PARAMETERS
file | URL
Specifies the path to the file or the URL to be opened. This is a mandatory argument.
--dry-run
Performs a dry run; instead of opening the file or URL, it prints the command that would have been executed. This is useful for debugging.
--help
Displays a brief help message and exits.
--manual
Displays the full manual page for xdg-open and exits.
--version
Displays the xdg-utils version information and exits.
DESCRIPTION
xdg-open is a desktop-agnostic command-line utility designed to open files or URLs using the user's default preferred application. It's a core component of the xdg-utils package, providing a standardized way to interact with graphical desktop environments from the command line. When supplied with a file path, xdg-open determines the file's MIME type and launches the appropriate application (e.g., a web browser for HTML, an image viewer for JPEGs, a document viewer for PDFs). For URLs, it typically opens the default web browser. This command effectively abstracts away the differences between various desktop environments like GNOME, KDE, and XFCE, offering a unified interface for launching resources. Its functionality is built upon the freedesktop.org specifications, ensuring consistent behavior across most modern Linux distributions.
CAVEATS
xdg-open is primarily intended for use within graphical desktop environments. Its functionality may be limited or non-existent in purely command-line or headless server setups without an X server.
Its behavior depends heavily on properly configured MIME types and default application associations within the desktop environment. If these are not set up correctly, xdg-open might fail to open resources or open them with unexpected applications.
It offers no direct options for controlling how an application opens a resource (e.g., new tab, specific window); this behavior is dictated by the default application itself.
EXIT STATUS
xdg-open returns 0 on success. A non-zero exit code indicates an error, such as an invalid argument (1), no application handler found for the file/URL (2), an issue with the underlying desktop environment (3), or a generic failure (4).
ENVIRONMENT VARIABLES
The behavior of xdg-open can be influenced by various environment variables that define preferred applications. For instance, BROWSER can specify the preferred web browser, VISUAL or EDITOR can specify the preferred text editor. If these are set, xdg-open may prioritize them when selecting an application.
HISTORY
The development of xdg-open stems from the freedesktop.org initiative, which aims to standardize aspects of desktop environments on Linux and other Unix-like systems. Before its widespread adoption, applications often had to rely on desktop-specific commands like gnome-open or kde-open to launch files and URLs. This led to fragmented codebases and compatibility issues across different desktop environments.
xdg-open was introduced as part of the xdg-utils package to provide a unified, desktop-agnostic interface for opening resources. It abstracts the underlying desktop environment's specific mechanisms, offering a consistent command for developers and users. Its role has grown significantly, making it the de facto standard for opening files and URLs from the command line in graphical Linux environments.
SEE ALSO
xdg-mime(1), xdg-settings(1), xdg-email(1), sensible-browser(1), gio(1) (specifically gio open), gnome-open(1) (older, superseded by xdg-open), kde-open(1) (older, superseded by xdg-open)