xdg-mime — command line tool for querying information about file type handling and adding descriptions for new file types
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
}
The xdg-mime program can be used to query information about file types and to add descriptions for new file types.
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.
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.
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.
--user
--system
--help
--manual
--version
An exit code of 0 indicates success while a non-zero exit code indicates failure. The following failure codes can be returned:
1
2
3
4
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