xdg-open is a desktop-independent tool to open a file or URL in the user's default application. Many applications invoke the command internally.
Inside a desktop environment (like GNOME, KDE, or Xfce), xdg-open simply passes the arguments to those desktop environment's file-opener application (eg. open, kde-open, or ). which means that the associations are left up to the desktop environment.
xdg-open is part of the official repositories. It is for use inside a desktop session only, and should not be run as root.package available in the
If you run xdg-open without a desktop environment, you should also install AUR for a faster alternative., or AUR and AUR from the
xdg-open is configured by the files mentioned in Default applications. xdg-mime modifies the local file
To query the mime type used by an existing file, use
$ xdg-mime query filetype file.ext
Reversely, to query the default desktop entry associated with a specific mime type, run
$ xdg-mime query default mime/type
Examples for mime/type can be:
inode/directory (file browser) image/jpeg (JPEG images) application/pdf (PDF viewer) or others
To change an associated desktop entry, use:
$ xdg-mime default application.desktop mime/type
For example set Thunar as the default file browser just run:
$ xdg-mime default Thunar.desktop inode/directory
Note that you should not specify the complete path, but only the name of the
This command can take multiple mime-types, allowing related files to be handled by the same program. The example below associates Emacs to all known source files:
$ xdg-mime default emacs.desktop $(grep '^text/x-*' /usr/share/mime/types)
Set the default browser
Internet protocols are using x-scheme-handler as first part of MIME-type. To show all available x-scheme-handler MIME-types and related to them *.desktop files in your system use toolAUR.
lsdesktopf --gm | grep x-scheme-handler
To set the default application for
http(s):// web URLs, write
$ xdg-mime default browser.desktop x-scheme-handler/http $ xdg-mime default browser.desktop x-scheme-handler/https
To do so for
$ xdg-mime default browser.desktop text/html
$ xdg-settings set default-web-browser browser.desktop
To test if this was applied successfully, try to open an URL with xdg-open as follows:
$ xdg-open https://archlinux.org
xdg-open uses desktop environment is detected. It can be invoked directly with:as a fallback ("generic") method if no
$ mimeopen -d /path/to/file
You are asked which application to use when opening
Please choose a default application for files of type text/plain 1) notepad (wine-extension-txt) 2) Leafpad (leafpad) 3) OpenOffice.org Writer (writer) 4) gVim (gvim) 5) Other...
Your answer becomes the default handler for that type of file. Mimeopen is installed as
Drop-in replacements and useful tools
|Name/Package||Method||Based on||Configuration file|
|AUR||MIME-type, regular expressions|
|AUR||MIME-type, name, regular expressions||SQLite database or, , etc||custom SQLite database or |
|AUR||MIME-type, name, regular expressions||or , etc|
|AUR||Regular expressions||, bash regex||custom|
|(rifle command)||MIME-type, name, regular expressions||custom|
xdg-utils. Those that do not can be symbolically linked to xdg-open in the user's
/usr/bin, but some applications hard-code the absolute path
/usr/bin/xdg-open. In this case, install AUR from the AUR and copy the replacement to
The .mailcap file format is used by mail programs such as
*/*; xdg-open "%s"
mimetype inpackage can display some mimetype-related information about a file.
$ mimetype file.ext
returns the mimetype of a file,
$ mimetype -d file.extension
returns a description of that mimetype.
When xdg-open fails to detect one of the desktop environments it knows about, it normally falls back to using
file -i, which uses only file contents to determine the mimetype, resulting in some file types not being detected correctly. With mimetype available, xdg-open will use that instead, with better detection results, as mimetype uses the information in the shared mime info database.
Some environment variables, such as
DESKTOP_SESSION, will change the behaviour of the default xdg-open. See Environment variables for more information.