Set Default Applications per File Type (xdg-mime)

Use xdg-mime default to choose which app opens a MIME type such as PDF, and query commands to discover types and current defaults.

Linuxmimexdgsettingsdefault-appsLow risk
Run `xdg-mime default okularApplication_pdf.desktop application/pdf` to make Okular the default PDF viewer.

01Command

Command
$ xdg-mime default okularApplication_pdf.desktop application/pdf

02What it does

First find the exact MIME type with `xdg-mime query filetype file.pdf`, then the .desktop name of the app you want from /usr/share/applications. The setting is per-user (stored in ~/.config/mimeapps.list) and applies to GNOME, KDE and XFCE alike; verify with `xdg-mime query default application/pdf`. Repeat for other types like text/plain or image/png to build up your preferred defaults.

03Risk

RiskLow risk
Requirementsxdg-utils (preinstalled). Find .desktop names with `ls /usr/share/applications | grep -i okular` and MIME types with `xdg-mime query filetype file.pdf`.
!Warning: The .desktop filename must match a real installed application — a typo makes xdg-mime accept it but double-click then does nothing or falls back to the previous app.

04Undo

Undo
$ xdg-mime default evince.desktop application/pdf

05Sources

  • xdg-mime(1) - Linux manual page
    Ubuntu Manpages · technical · 2026-09-17
    Evidence: xdg-mime default sets the default application for a MIME type, and xdg-mime query filetype/default reports the MIME type and current default handler.

Last verified: 2026-09-18 · Category: System & Settings