This page was exported from Furor Teutonicus [ ]
Export date: Tue Sep 21 11:18:38 2021 / +0000 GMT

How to add a custom filetype to Linux

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:
cd ~/.local/share/mime/packages

vi message-rfc822.xml

The contents should be these:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="">
<mime-type type="message/rfc822">
<comment>MHTML web archive</comment>
<icon name="application-rss+xml"/>
<glob pattern="*.mht"/>
<glob pattern="*.MHT"/>
<glob pattern="*.mhtml"/>

And we have to update the MIME database:
update-mime-database ~/.local/share/mime

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:
gtk-update-icon-cache -f -t ~/.icons/Roedor

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:

Excerpt: How to add a custom filetype in the Linux desktop environment, with a custom MIME type, custom extension, and custom icon.
Post date: 2013-12-03 19:58:03
Post date GMT: 2013-12-03 18:58:03
Post modified date: 2013-12-03 20:05:50
Post modified date GMT: 2013-12-03 19:05:50
Powered by [ Universal Post Manager ] plugin. HTML saving format developed by gVectors Team