Linux – How to configure Linux to open files by extension

desktop-environmentsfile associationlinux

The various Linux's desktops open files according to their mime type. This is a very nice feature but I also need to open them by extension (as with Windows).

For instance, I want to open every xxxxx.vnc files with a specific program when I double-click on them.
I use xfce but I don't think it differs from Gnome or KDE because all of them use the same configuration files (defaults.list and mimeapps.list).
If possible the settings are user specific, not system wide.

I've found some very poor informations about that, and all are system wide, so may be wiped out by some updates.

Best Answer

The answer is simple but can't be guessed:

  1. Create a file named vnc-mime.xml (whatever name, but must obey some patern)
  2. Inside the file:

    <?xml version="1.0"?>  
    <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>  
        <mime-type type="application/extension-vnc">  
            <comment>.vnc file</comment>  
            <glob pattern="*.vnc"/>  
        </mime-type>  
    </mime-info>  
    
  3. Run "xdg-mime install vnc-mime.xml" as the local user. (or as root for the settings to be system-wide? Not tested)
  4. The mime type is now registered. Use your favorite file manager to select the program you want to run (with "Open as...")
Related Question