$linuxjunkies
>

xdg-mime(1)

Query and set MIME type associations for files and URLs on the desktop.

UbuntuDebianFedoraArch

Synopsis

xdg-mime query [filetype|default] MIME-TYPE
xdg-mime default APPLICATION MIME-TYPE...
xdg-mime install [--mode MODE] [--novendor] MIMETYPES-FILE

Description

xdg-mime is used to query MIME type information and set default applications for handling specific MIME types on freedesktop.org-compliant desktops. It provides a uniform interface across different desktop environments like GNOME, KDE, and others.

Common tasks include looking up what MIME type a file has, finding the default application for a MIME type, and setting a new default application for handling particular file types.

Common options

FlagWhat it does
query filetype FILEOutput the MIME type of the specified file
query default MIME-TYPEOutput the default application for the given MIME type
default APPLICATION MIME-TYPESet APPLICATION as the default handler for MIME-TYPE(s)
install [--mode MODE]Install MIME type definitions from a .xml file (user or system mode)
--novendorSkip the vendor prefix when installing MIME types

Examples

Check the MIME type of a PDF file (outputs application/pdf)

xdg-mime query filetype document.pdf

Show which application is currently set as the default PDF handler

xdg-mime query default application/pdf

Set Firefox as the default application for HTML and XHTML files

xdg-mime default firefox.desktop text/html application/xhtml+xml

Set GNOME Files (Nautilus) as the default directory opener

xdg-mime default org.gnome.Nautilus inode/directory

Set VLC to handle MP4 and Matroska video files by default

xdg-mime default vlc.desktop video/mp4 video/x-matroska

Install custom MIME type definitions in user-specific configuration

xdg-mime install --mode user custom-mimetypes.xml

Related commands