Name

xdg-mime — command line tool for querying information about file type handling and adding descriptions for new file types

Synopsis

xdg-mime query { filetype | default } FILE

xdg-mime install { --user | --system } mimetypes-file

xdg-mime uninstall { --user | --system } mimetypes-file

xdg-mime { --help | --manual | --version }

Description

The xdg-mime program can be used to query information about file types and to add descriptions for new file types.

Commands

query

Returns information related to the file type of FILE.

The query option is for use inside a desktop session only. It is not recommended to use xdg-mime query as root.

The following queries are supported:

filetype: Returns the file type of FILE in the form of a MIME type.

default: Returns the default application that the desktop environment uses for opening FILE. The default applications is identified by its *.desktop file.

install
Adds the file type descriptions provided in mimetypes-file to the desktop environment. mimetypes-file must be a XML file that follows the freedesktop.org Shared MIME-info Database specification and that has a mime-info element as its document root. For each new file type one or more icons with name major-minor must be installed with the xdg-icon-resource command in the mimetypes context. For example the application/vnd.oasis.opendocument.text filetype requires an icon by the name of application-vnd.oasis.opendocument.text to be installed.
uninstall
Removes the file type descriptions provided in mimetypes-file and previously added with xdg-mime install from the desktop environment. mimetypes-file must be a XML file that follows the freedesktop.org Shared MIME-info Database specification and that has a mime-info element as its document root.

Options

--user
Adds or removes file type descriptions for the current user only.
--system
Adds or removes file type descriptions for all users on the system. Usually only root is allowed to do this.
--help
Show command synopsis.
--manual
Show this manualpage.
--version
Show the xdg-utils version information.

Exit Codes

An exit code of 0 indicates success while a non-zero exit code indicates failure. The following failure codes can be returned:

1
Error in command line syntax.
2
One of the files passed on the command line did not exist.
3
A required tool could not be found.
4
The action failed.

See Also

xdg-icon-resource(1), xdg-desktop-menu(1)

Examples

xdg-mime query filetype /tmp/foobar.png

Prints the MIME type of the file /tmp/foobar.png

xdg-mime query default /tmp/foobar.png

Prints the name of the .desktop file of the application which is registered to open files of the MIME type the file /tmp/foobar.png has

xdg-mime install --system diff.xml

Adds a file type description for "diff"-files for all users on the system. The file type description could look as folows.

diff.xml:

<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  <mime-type type="text/x-diff">
    <comment>Differences between files</comment>
    <glob pattern="*.diff"/>
    <glob pattern="*.patch"/>
  </mime-type>
</mime-info>

An icon for this new file type must alsobe installed, for example with:

xdg-icon-resource install --system --context mimetypes --size 64 text-x-diff.png