Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I configure Ubuntu to open files of a given type (e.g. file.tex) with a given program (e.g. emacs)?

share|improve this question

3 Answers 3

up vote 8 down vote accepted

Run nautilus, right click one of those files, choose "Properties" from the context menu and set your preferences with the "Open with" option.

share|improve this answer
    
The thing I really like is if you have just three apps listed there, they appear in the first level of the right click menu. Any more, and on the default one appears with the others in a sub menu. I'm constantly removing apps from the menu - I don't need 5 text editors and 5 browsers listed for a HTML file ;) –  DisgruntledGoat Aug 13 '09 at 9:41
    
I know exactly what you mean. –  innaM Aug 13 '09 at 9:44

Instead of editing defaults.list, I find it easier to use the xdg-mime program. Looking up the pdf viewer, seeing its adobe, and switching it to KPDF:

$xdg-mime query default application/pdf
AdobeReader.desktop
$xdg-mime default kde-kpdf.desktop application/pdf
$xdg-mime query default application/pdf
kde-kpdf.desktop

And you can use xdg-open to open a file with your preferred application:

$xdg-open file.pdf
share|improve this answer
1  
+1. Excellent. I wasn't aware of this tool. I'd prefer this too to editing the file directly. –  nagul Aug 12 '09 at 10:38

You can use the Properties tab on a file to change the program used to open it, as Manni pointed out.

Edit: Have a look at Chris089's answer. I'd prefer that to directly editing the files as I suggested below. It might still be useful to know what the mime-types are and where the associations lie, but I'd use the tool to modify the file.

However, if you want a text-based solution, or even to have a look at how file-associations are configured for different types:

  • The file associations are stored for each individual user in ~/.local/share/applications/default.list. You can edit this to point to a .desktop file (which represents the executable)

$ cat ~/.local/share/applications/defaults.list
[Default Applications]
application/vnd.google-earth.kml+xml=Google-googleearth.desktop
application/keyhole=Google-googleearth.desktop
application/earthviewer=Google-googleearth.desktop
application/vnd.google-earth.kmz=Google-googleearth.desktop

  • At the global system-wide level, associations are held in /usr/share/applications/defaults.list. So, if I wanted to effect a system-wide change for all audio files for example, this is where I'd need to look to get all the mime-types. You then have a choice between changing the file types directly here, or overriding them in your local defaults.list

$ cat /usr/share/applications/defaults.list | grep ^audio
audio/3gpp=totem.desktop
audio/ac3=totem.desktop
audio/AMR=totem.desktop
audio/AMR-WB=totem.desktop
audio/basic=totem.desktop
audio/midi=totem.desktop
audio/mp4=totem.desktop
audio/mpeg=totem.desktop
audio/mpegurl=totem.desktop
audio/ogg=totem.desktop
audio/prs.sid=totem.desktop
audio/vnd.rn-realaudio=totem.desktop
audio/x-ape=totem.desktop
audio/x-flac=totem.desktop
audio/x-gsm=totem.desktop
audio/x-it=totem.desktop
audio/x-m4a=totem.desktop
audio/x-matroska=totem.desktop
audio/x-mod=totem.desktop
audio/x-mp3=totem.desktop
audio/x-mpeg=totem.desktop
audio/x-mpegurl=totem.desktop
audio/x-ms-asf=totem.desktop
audio/x-ms-asx=totem.desktop
audio/x-ms-wax=totem.desktop
audio/x-ms-wma=totem.desktop
audio/x-musepack=totem.desktop
audio/x-pn-aiff=totem.desktop
audio/x-pn-au=totem.desktop
audio/x-pn-realaudio=totem.desktop
audio/x-pn-realaudio-plugin=totem.desktop
audio/x-pn-wav=totem.desktop
audio/x-pn-windows-acm=totem.desktop
audio/x-realaudio=totem.desktop
audio/x-real-audio=totem.desktop
audio/x-sbc=totem.desktop
audio/x-scpls=totem.desktop
audio/x-speex=totem.desktop
audio/x-tta=totem.desktop
audio/x-wav=totem.desktop
audio/x-wavpack=totem.desktop
audio/x-vorbis=totem.desktop
audio/x-vorbis+ogg=totem.desktop
audio/x-xm=totem.desktop

Here is the Desktop Entry Specification document that details the need for and use of a .desktop file (instead of using the path to the executable ).

share|improve this answer
    
In Ubuntu 12.10 there isn´t ~/.local/share/applications/defaults.list I had to edit ~/.local/share/applications/mimeapps.list –  rodvlopes Jul 18 '13 at 13:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.