What is xdg open

Last updated: April 1, 2026

Quick Answer: xdg-open is a Linux command-line utility that opens files and URLs with their default applications, automatically selecting the appropriate program based on the file type and the desktop environment configuration.

Key Facts

Overview

xdg-open is a command-line utility found on Linux systems that provides a simple, standardized way to open files and URLs with their associated default applications. The name xdg stands for X Desktop Group, which later became part of the freedesktop.org project that develops open standards for desktop environments. This command is fundamental to the Linux desktop ecosystem for opening files programmatically without explicitly specifying which application to use.

How xdg-open Works

When you execute the xdg-open command with a file or URL as an argument, the system performs several operations. First, it determines the MIME type (file type) of the file being opened. It then consults the system's MIME type configuration files and desktop environment settings to identify the default application associated with that file type. Once the appropriate application is identified, xdg-open launches that application with the file as an argument. For example, typing xdg-open document.pdf would open the PDF file with whatever PDF reader is configured as the default, whether that's Adobe Reader, Evince, or another application.

Common Usage Examples

xdg-open is used in numerous contexts. Web developers might use it in build scripts to automatically open newly generated documentation in the default web browser. System administrators use it in shell scripts and system configurations to open files consistently across different user environments. Desktop applications use xdg-open to open files selected by users in file dialogs. The command also works with URLs, allowing scripts to open web links in the default browser with xdg-open https://example.com, making it useful for creating desktop shortcuts and application launchers that need to be portable across different Linux distributions.

Desktop Environment Independence

A key advantage of xdg-open is its desktop environment independence. Different Linux desktop environments like GNOME, KDE, XFCE, and others manage default applications differently. Rather than writing separate code or scripts for each environment, developers can use xdg-open and be confident it will work consistently. The xdg-open command automatically detects the running desktop environment and uses the appropriate mechanism to open files, whether that's GNOME's default application settings, KDE's configuration system, or another environment's configuration method.

Configuration and Customization

Users can customize which applications open which file types through their desktop environment's settings. In GNOME, this is typically done through the Files application's properties dialog or system settings. In KDE, it can be configured through the System Settings. Once configured, xdg-open respects these preferences. Additionally, users can manually specify a different application using the --choose flag to have xdg-open display a dialog allowing selection of the application to use, providing flexibility when multiple applications can open the same file type.

Related Questions

How do you use xdg-open in a shell script?

You use xdg-open in shell scripts by invoking it with the file or URL as an argument, such as `xdg-open /path/to/file.txt`. It runs asynchronously, returning control to the script immediately while the file opens in the background.

What happens if no default application is configured for a file type?

If no default application is configured, xdg-open typically displays an error message or, in some cases, may show a dialog allowing you to choose an application to open the file with, depending on the desktop environment.

Can xdg-open open URLs?

Yes, xdg-open can open URLs and will launch them in the default web browser. You can use it with commands like `xdg-open https://example.com` to open websites from the command line or scripts.

Sources

  1. Wikipedia - Freedesktop.org CC-BY-SA-4.0
  2. Linux man pages - xdg-open GPL