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 using realpath as a preprocessor. - Prefix known relative filepaths with a "./". For example using sed -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 be user or system. in user mode the file is (un)installed for the current user only. in system mode the file is (un)installed for all users on the system. usually only root is allowed to install in system mode. the default is to use system mode when called by root and to use user mode when called by a non-root user. she reads the room. ๐Ÿ’–
  • --novendor โ€” normally, xdg-mime checks 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 the xdg-utils version information.

๐ŸŒธ ENVIRONMENT VARIABLES ๐ŸŒธ

xdg-mime honours the following environment variables:

  • XDG_UTILS_DEBUG_LEVEL โ€” setting this environment variable to a non-zero numerical value makes xdg-mime do more verbose reporting on stderr. 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 are user and system.

๐Ÿ”ฅ 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. 1 โ€” Error in command line syntax.
  2. 2 โ€” One of the files passed on the command line did not exist.
  3. 3 โ€” A required tool could not be found.
  4. 4 โ€” The action failed.
  5. 5 โ€” No permission to read one of the files passed on the command line.

๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹


โญ 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 ยฉ 2006


๐Ÿ’œ NOTES ๐Ÿ’œ

  1. Shared MIME database specification โ€” http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec/
  2. 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