MIME Types – How to Completely Remove a MIME Association in Linux

mime-types

I'm running Arch Linux and KDE. I have installed Arch KDE on several devices and in the usual case there is no specific mime-type association for .pub files (which are public keys in my case). They will be opened by the default handler for plain text documents. This is what I expect to see on my standard Arch Linux install:

$ xdg-mime query filetype id_rsa_test.pub
text/plain

However, on my main desktop, .pub files are associated with ms-publisher.

$ xdg-mime query filetype id_rsa_test.pub
application/vnd.ms-publisher

I want to remove this association completely. Here are some of the places I found evidence of this association:

$ grep -irl '.pub' ./.local/share/mime/
./.local/share/mime/packages/application-vnd.ms-publisher.xml
./.local/share/mime/application/vnd.ms-publisher.xml
./.local/share/mime/globs
./.local/share/mime/globs2
./.local/share/mime/types
./.local/share/mime/mime.cache

$ sudo grep -irl 'ms-publisher' /usr
/usr/share/applications/mimeinfo.cache
/usr/share/mime/packages/freedesktop.org.xml
/usr/share/mime/application/vnd.ms-publisher.xml
/usr/share/mime/globs
/usr/share/mime/globs2
/usr/share/mime/subclasses
/usr/share/mime/types
/usr/share/mime/mime.cache
/usr/share/icons/breeze/mimetypes/64/application-vnd.ms-publisher.svg
/usr/share/icons/breeze/mimetypes/22/application-vnd.ms-publisher.svg
/usr/share/icons/breeze/breeze-icons.rcc
/usr/share/icons/breeze/icon-theme.cache
/usr/share/icons/breeze-dark/mimetypes/22/application-vnd.ms-publisher.svg
/usr/share/icons/breeze-dark/breeze-icons-dark.rcc
/usr/share/icons/breeze-dark/icon-theme.cache
/usr/lib/libreoffice/share/xdg/draw.desktop

According to the xdg-mime man page, the uninstall command might do the trick. In my case at least, the uninstall command has no effect.

# xdg-mime uninstall /usr/share/mime/application/vnd.ms-publisher.xml
# echo $?
0

# sudo grep -irl 'ms-publisher' /usr
/usr/share/file/misc/magic.mgc
/usr/share/applications/mimeinfo.cache
/usr/share/mime/packages/freedesktop.org.xml
/usr/share/mime/application/vnd.ms-publisher.xml
/usr/share/mime/globs
/usr/share/mime/globs2
/usr/share/mime/subclasses
/usr/share/mime/types
/usr/share/mime/mime.cache
/usr/share/icons/breeze/mimetypes/64/application-vnd.ms-publisher.svg
/usr/share/icons/breeze/mimetypes/22/application-vnd.ms-publisher.svg
/usr/share/icons/breeze/breeze-icons.rcc
/usr/share/icons/breeze/icon-theme.cache
/usr/share/icons/breeze-dark/mimetypes/22/application-vnd.ms-publisher.svg
/usr/share/icons/breeze-dark/breeze-icons-dark.rcc
/usr/share/icons/breeze-dark/icon-theme.cache
/usr/lib/libreoffice/share/xdg/draw.desktop

# grep -irl '.pub' /usr/share/mime/
/usr/share/mime/packages/freedesktop.org.xml
/usr/share/mime/packages/calibre-mimetypes.xml
/usr/share/mime/application/pkcs7-mime.xml
/usr/share/mime/application/pkcs8-encrypted.xml
/usr/share/mime/application/epub+zip.xml
/usr/share/mime/application/x-pkcs7-certificates.xml
/usr/share/mime/application/pkcs8.xml
/usr/share/mime/application/pkcs10.xml
/usr/share/mime/application/pkcs12.xml
/usr/share/mime/application/vnd.ms-publisher.xml
/usr/share/mime/globs
/usr/share/mime/globs2
/usr/share/mime/magic
/usr/share/mime/subclasses
/usr/share/mime/types
/usr/share/mime/generic-icons
/usr/share/mime/mime.cache

For my question, I want to know generally how to remove any mime-type association from my system using only CLI tools.

EDIT: response to answer:

On a new user account I show the following:

sudo pacman -Qs shared-mime-info
local/shared-mime-info 1.15-2
    Freedesktop.org Shared MIME Info

$ xdg-mime query filetype id_rsa_test.pub
text/plain

$ xdg-mime query default text/plain
atom.desktop

$ less ~/.config/mimeapps.list
/home/deleteme/.config/mimeapps.list: No such file or directory

This system has been updated multiple times (every day) and the ms-publisher association with .pub files has not come back. Note that this system has shared-mime-info installed and I am able to open public key files with a plain text editor, as I expect. In another user account on this system, I have my preferred association via an entry in ~/.config/mimeapps.list for that user.

$ xdg-mime query default text/plain
org.kde.kate.desktop

Back to the main question: How do I completely remove the association of .pub files with Okular and/or Libre Office Draw at the system level? Even if that's not an approved method, how do I do it?

Best Answer

.pub files will be opened by the default handler for plain text documents. This is what I expect to see on my standard Arch Linux

There is no reason you should expect this. The shared-mime-info package assumes .pub is a Microsoft Publisher document. If you think the default should be plain/text, then you need to report this upstream.

I, myself, think it's a bug and they should not make a M$ proprietary format extension a priority over a GNU/linux native file extension. Or better still to use use magic in addition to glob

I want to know generally how to remove any mime-type association from my system using only CLI tools

You shouldn't remove system-wide mime-type associations at all. Even if you managed to do it, it would come back later with system updates.

What you should do is to add your own mime type that overwrites the system one. As you already know from your other question here, you can use glob-deleteall to overwrite the previous definitions

Related Question