From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

This page describes various command-line programs for managing and using default applications for particular MIME types, in the context of standards/specifications by freedesktop.org, previously known as the X Desktop Group.

Most of the programs described in this page are provided by the x11-misc/xdg-utils package; exceptions are noted.



The xdg-open(1) program can be used to open a file or URL in the default application for that resource:

user $xdg-open file.txt

This will open file.txt in the preferred application for text/plain files, e.g. Kate or GEdit.

This will open https://www.gentoo.org/ in the preferred Web browser, e.g. Firefox.


The xdg-mime(1) program is the primary way to manage default desktop applications from the command line.

It can be used to query the MIME type of file:

user $xdg-mime query filetype image.ext

Note, however xdg-mime takes a file's extension at face value, so if the file image.ext in the previous example was renamed to image.jpg, xdg-mime reports an incorrect file type:

user $xdg-mime query filetype image.jpg

file(1), however, will report the correct file type:

user $file image.jpg
image.jpg: TIFF image data, big-endian

xdg-mime can also be used to query the default application for a particular MIME type:

user $xdg-mime query default image/tiff

To set the default application for a MIME type, specify the relevant .desktop file:

user $xdg-mime default nsxiv.desktop image/tiff

Available .desktop files can be found in /usr/share/applications/ and (by default) ~/.local/share/applications/. However, as the xdg-mime(1) man page notes,

[t]he application's desktop file must list support for all the MIME types that it wishes to be the default handler for.


The xdg-settings(1) program can be used to set the default browser:

user $xdg-settings set default-web-browser firefox-bin.desktop

It can also be used to set the default handler for a particular URL scheme, e.g. mailto:

user $xdg-settings set default-url-scheme-handler mailto balsa.desktop

See also