xdg-open is a desktop-independent tool for configuring the default applications of a user. Many applications invoke the
xdg-open command internally.
Inside a desktop environment (e.g. GNOME, KDE, Xfce, etc.),
xdg-open simply passes the arguments to that desktop environment's file-opener application (
exo-open, respectively), which means that the associations are left up to the desktop environment. When no desktop environment is detected (for example when one runs a standalone window manager, e.g. Openbox),
xdg-open will use its own configuration files.
xdg-open is part of the official repositories. xdg-open is for use inside a desktop session only. It is not recommended to use xdg-open as root.package available in the
The config file
xdg-open uses configuration files located at
$XDG_DATA_HOME/applications/mimeapps.list (for a single user;
$XDG_DATA_HOME defaults to
/usr/share/applications/defaults.list (system wide). Its format is as follows:
[Default Applications] mimetype=desktopfile1;desktopfile2...
[Default Applications] text/html=firefox.desktop inode/directory=kde4-dolphin.desktop;Thunar.desktop;nautilus.desktop
The best way to look up the MIME type is to read the
MimeTypes list in your application's
.desktop file (see Desktop Entries for details).
Some tools are available to edit the configuration files:
- To get mime type of
$ xdg-mime query filetype photo.jpg
- To get default
.desktopfile starter for
$ xdg-mime query default image/jpeg
- To make Thunar the default file-browser, i.e. the default application for opening folders:
$ xdg-mime default Thunar.desktop inode/directory
- To use as the default PDF viewer:
$ xdg-mime default xpdf.desktop application/pdf
Previous command should create an entry in your local MIME database:
[Default Applications] application/pdf=xpdf.desktop
Setting default browser for xdg-open
This can be tricky to find, so to save you some work:
$ xdg-mime default firefox.desktop x-scheme-handler/http $ xdg-mime default firefox.desktop x-scheme-handler/https
$ xdg-mime default firefox.desktop text/html
Drop-in replacements and useful tools
|Name/Package||Description||Based on||Configuration file|
|AUR||A simple, regex-based xdg-open replacement.||custom|
|AUR||Opens objects in associated applications by matching regular expressions against object name or MIME-type.||(but alternatives can be configured)||custom|
|AUR||An intelligent and suckless replacement for xdg-open.||custom|
|AUR||Open files by MIME-type or file name using regular expressions. It can be used on its own or throughAUR.|| standard |
|AUR||A working replacement for xdg-open.||custom|
.mailcap file format used by the mutt mail program is way easier to read and write. The AUR package from the AUR provides a executable that could be easily symlinked to
/usr/bin/xdg-open, but that parser is unable to handle directories or links. The simplest solution would be to install mimeo from the AUR too and create a
/usr/bin/xdg-open with the following content:
#!/bin/sh run-mailcap $1 || mimeo $1
Then use the
~/.local/share/applications/ to associate URLs and folders with applications and the
.mailcap file for normal mimetypes.
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.
Some environment variables, such as
DESKTOP_SESSION, will change the behaviour of the default xdg-open. See Environment Variables for more information.