How to Check the Default Application for a MIME Type on Linux

2025-09-24
3 min read

Introduction

On Linux desktop environments, managing which application opens a specific type of file is a common task. While setting a default application is straightforward, you might first want to check the current default before making a change. The xdg-utils suite provides a standard way to handle these desktop integrations from the command line.

This article explains how to use the xdg-mime command to query the system and find out which application is currently registered as the default for a given file type, also known as a MIME type.

The Solution: Using xdg-mime query

To check the current default application for a specific file type, you use the xdg-mime query default command followed by the MIME type you are interested in.

For example, to find the default application for plain text files (text/plain), run the following command in your terminal:

xdg-mime query default text/plain

The command will output the .desktop file name of the default application, such as org.gnome.TextEditor.desktop or code.desktop.

How It Works

The command is part of the xdg-utils package, which aims to provide a set of standardized tools for integrating applications with the desktop environment, regardless of which one you use (e.g., GNOME, KDE, XFCE).

Each part of the command has a specific role:

  • xdg-mime: The primary command-line tool for querying and setting information about file types and default application handlers.
  • query: The action specifying that you are requesting information from the system.
  • default: A parameter that narrows the query to find the default handler for the specified MIME type.
  • text/plain: The identifier for the file type. The system identifies files by their content (MIME type) rather than just their extension (like .txt).

Bonus Tip: Finding a File’s MIME Type

You may not always know the exact MIME type for a particular file. In such cases, the file command is an invaluable utility to identify it.

To find the MIME type for any file, use the following command structure:

file --mime-type -b your_file_name

Example

If you have a shell script named backup.sh and want to find its MIME type, you would run:

file --mime-type -b backup.sh

The expected output would be text/x-shellscript. With this information, you can then query for its default application:

xdg-mime query default text/x-shellscript

The flags used with the file command are:

  • --mime-type: Instructs file to output only the MIME type string.
  • -b or --brief: Prevents the filename from being prepended to the output line, giving you a clean result.

Conclusion

Checking the default application for any file type on Linux is a simple task with the right command. By using xdg-mime query default <MIME-TYPE>, you can quickly retrieve the current file handler. When you’re unsure of a file’s MIME type, the file --mime-type -b <FILENAME> command serves as a perfect companion tool to identify it first. These utilities provide a standardized and reliable way to manage desktop file associations directly from the command line.