XDG-MIME(1)
๐ XDG-MIME(1) โ the xdg-mime manual, but make it make sense ๐
okay bestie, sit down, we're doing file types today and honestly? this one's a bop. โจ
xdg-mime is the command line tool for querying information about file type handling and adding descriptions for new file types. that's it, that's the whole job. she queries, she installs, she uninstalls, she serves. ๐
๐ SYNOPSIS ๐
xdg-mime query {filetype FILE | default mimetype}
xdg-mime default application mimetype(s)
xdg-mime install [--mode mode] [--novendor] mimetypes-file
xdg-mime uninstall [--mode mode] mimetypes-file
xdg-mime {--help | --manual | --version}
โจ DESCRIPTION โจ
so xdg-mime is that girl for asking questions about file types (like, what even are you, mysterious download.png) and for teaching your desktop about brand new file types that didn't exist before. lowkey iconic. ๐ฆ
๐ COMMANDS ๐
query file
gives you the file type of FILE, dressed up as a MIME type. like "hey bestie this is image/png" energy. ๐ซถ
โ ๏ธ important tea: FILE names that start with a-get rejected. rude but true. here's how to dodge it: - Pass absolute paths, i.e. by usingrealpathas a preprocessor. - Prefix known relative filepaths with a"./". For example usingsed -E 's|^[^/]|./\0|'as a preprocessor.
also: the query file option is for use inside a desktop session only. and it is not recommended to use xdg-mime query file as root. like, don't do it, bestie, put the sudo down. ๐
query default
tells you the default application your desktop environment uses for opening files of type mimetype. the default application is identified by its *.desktop file. cute, right?
now, real talk: the value returned by this command may or may not match the application launched by xdg-open, because xdg-open hands over to desktop specific openers most of the time, and those may implement their own logic. so don't come for her when the vibes differ. ๐ญ
the query default option is for use inside a desktop session only. and again, not recommended to use xdg-mime query default as root.
default
asks the desktop environment to make application the default application for opening files of type mimetype. you can crown one app for several file types at once by listing multiple mimetypes. main character energy, honestly. ๐
application is the desktop file id of the application and has the form vendor-name.desktop. and no skipping steps: application must already be installed in the desktop menu before it can be made the default handler. also the application's desktop file must list support for all the MIME types it wishes to be the default handler for. no bluffing. ๐
requests to make an application a default handler may be subject to system policy or approval by the end-user. xdg-mime query can be used to verify whether an application is the actual default handler for a specific file type. always verify, bestie. ๐ง
Security Note: Never set a handler that will blindly execute code or commands from the file being handled. Such behaviour will sooner than later lead to unintended code execution โ i.e. through a curious user trying to inspect a freshly downloaded file but running it by accident. ๐๐๐
Keeping opening and executing separate actions helps with people protecting themselves from malware โ the default handler is an opener, not a runner. tattoo it on your brain fr fr.
the default option is for use inside a desktop session only, and โ you guessed it โ not recommended to use xdg-mime default as root.
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. fancy but mandatory.
for each new file type, one or more icons with name type-subtype must be installed with the xdg-icon-resource command in the mimetypes context. for example the filetype application/vnd.oasis.opendocument.text requires an icon named application-vnd.oasis.opendocument.text to be installed (unless the file type recommends another icon name). yeah she's specific. ๐ฏ
uninstall
removes the file type descriptions provided in mimetypes-file, and previously added with xdg-mime install, from the desktop environment. we love a clean exit. ๐ธ
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. same rules, reverse direction.
๐ OPTIONS ๐
--mode modeโ mode can beuserorsystem. inusermode the file is (un)installed for the current user only. insystemmode the file is (un)installed for all users on the system. usually only root is allowed to install insystemmode. the default is to usesystemmode when called by root and to useusermode when called by a non-root user. she reads the room. ๐--novendorโ normally,xdg-mimechecks to ensure that the mimetypes-file to be installed has a proper vendor prefix. this option can be used to disable that check. a vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated with a dash ("-"). companies and organizations are encouraged to use a word or phrase, preferably the organizations name, for which they hold a trademark as their vendor prefix. the purpose of the vendor prefix is to prevent name conflicts. โจ--helpโ show command synopsis. short king. ๐--manualโ show this manual page. (hi, you're here, that's this.)--versionโ show thexdg-utilsversion information.
๐ธ ENVIRONMENT VARIABLES ๐ธ
xdg-mime honours the following environment variables:
XDG_UTILS_DEBUG_LEVELโ setting this environment variable to a non-zero numerical value makesxdg-mimedo more verbose reporting onstderr. setting a higher value increases the verbosity. louder = more. ๐ขXDG_UTILS_INSTALL_MODEโ this environment variable can be used by the user or administrator to override the installation mode. valid values areuserandsystem.
๐ฅ EXIT CODES ๐ฅ
an exit code of 0 indicates success while a non-zero exit code indicates failure. vibe check passed vs. vibe check failed essentially. 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.5โ No permission to read one of the files passed on the command line.
๐ฆ SEE ALSO ๐ฆ
xdg-icon-resource(1)xdg-desktop-menu(1)- Shared MIME database specification[1]
- MIME applications associations specification[2]
โญ EXAMPLES โญ
okay this is the part where it all clicks, watch:
xdg-mime query filetype /tmp/foobar.png
prints the MIME type of the file /tmp/foobar.png, in this case image/png. ๐ผ๏ธ
xdg-mime query default image/png
prints the .desktop filename of the application which is registered to open PNG files.
xdg-mime install shinythings-shiny.xml
adds a file type description for "shiny"-files. "shinythings-" is used as the vendor prefix. the file type description could look as follows. ๐
shinythings-shiny.xml:
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/x-shiny">
<comment>Shiny new file type</comment>
<glob pattern="*.shiny"/>
<glob pattern="*.shi"/>
</mime-type>
</mime-info>
an icon for this new file type must also be installed, for example with:
xdg-icon-resource install --context mimetypes --size 64 shiny-file-icon.png text-x-shiny
see? set. slay. ๐
๐ AUTHORS ๐
- Kevin Krammer โ Author.
- Jeremy White โ Author.
๐ COPYRIGHT ๐
Copyright ยฉ 2006
๐ NOTES ๐
- Shared MIME database specification โ
http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec/ - MIME applications associations specification โ
http://www.freedesktop.org/wiki/Specifications/mime-apps-spec/
and that's the whole page bestie, no cap. this was xdg-utils version 1.0, dated 12/06/2025 โ periodt. ๐โจ๐
๐ฆ where this page comes from
- arch rolling: xdg-utils 1.2.1-2 ยท MIT
- ubuntu resolute: xdg-utils 1.2.1-2ubuntu2 ยท MIT
- ubuntu stonking: xdg-utils 1.2.1-2ubuntu2 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms