How to add a custom filetype to Linux

— door Evert Mouw

add-iconIf you are a Linux user, you might encounter the situation where you really want to add a custom filetype to your graphical environment. This article will help you do it without relying on specific tools, so it should work with all Linux distributions and in most graphical environments. I used Arch Linux with XFCE.

This post was earlier (2013-07-15) posted on TechMonks, of which I am a co-author.

In this example, we will add support for MHTML / MHT files.

Note that the MIME type for MHTML is not well agreed upon. Used MIME types include:

  • multipart/related
  • application/x-mimearchive
  • message/rfc822

According to a StackOverflow question, message/rfc822 should be used. A recent discussion on FreeDesktop, however, recommends application/x-mimearchive as a subtype of multipart/related. I will use message/rfc822 in the examples below and have added this unclarity to the Wikipedia article.

Add a custom MIME type

This adds a custom MIME type for the current user.

First, we open a new file:

The contents should be these:

And we have to update the MIME database:

Add a custom icon

In the MIME type added in the example above, I used the existing application-rss+xml icon for the MHTML files. You might want to edit the icon. That icon needs to be stored somewhere in the ~/.icons directory. For example, when using the Roedor icon set, see:

After editing the icon, upate the icon cache:

It is also possible to use a generic icon, independent of the theme being used, by setting an override. I have not explored this further because I did not need it, and because I saw fragmented and insonsistent information about this on the web.

Set the application used to open the MIME filetype

Changing the application used for opening files with this MIME type depends partly on the desktop environment used.

In XFCE, for example, go to Applications –> MIME Type Editor, or right-click a file.

MIME type editor

More resources: