11

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.

8
  • Why do you need extension and not mime type? Do you have a file that is for example a .png, but file(1) returns a different mime type for? Aug 9, 2012 at 18:19
  • Why do you think this question is off topic @JustinDearing? AFAICT, this question is perfectly on topic on Super User, as it concerns computer software. Unless Gregory himself decides he wants it migrated somewhere else, it should stay here.
    – Daniel Beck
    Aug 9, 2012 at 18:23
  • I flagged this question as off topic, it belongs on unix.stackexchange.com Aug 9, 2012 at 18:29
  • @DanielBeck I meant no offense. I thought that would be a better place for it. I flagged it, the moderators can decide. As you can tell, I did provide helpful comments, and depending on his responses I will try to provide an answer to the best of my abilities. Aug 9, 2012 at 18:30
  • @JustinDearing I saw that flag, and that's why I asked — I could have be missing something that makes this off topic. I saw that you did not mean to "steal" the question, as many others do, easily identified by high-rep accounts on the supposed destination site. We have a lot of users on this site that can answers related to Unix/Linux though, so there's no reason to move it yet. The situation's different if no responses are posted for a week or so.
    – Daniel Beck
    Aug 9, 2012 at 18:36

1 Answer 1

10

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...")

3
  • 3
    Bertrand, I cleaned up the XML in your answer for you. You can see how I did it by clicking the edit button. I used a code block to provide a fixed-width font and to stop processing of angle brackets or other markdown/formatting. The markdown formatting guide has some wonderful examples of all the advanced things you can do in markdown. Hope that helps! Aug 10, 2012 at 17:20
  • Is there a commend-line version for this? I want to automatically open files based on their type from typing into an xterm.
    – Eyal
    Nov 27, 2012 at 13:32
  • before it works (step 4) you maybe have to kill all running file managers. for me i had to killall nemo
    – iRaS
    Mar 17, 2016 at 7:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .