11

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

3 Answers 3

15

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

2
  • 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 ;) Aug 13, 2009 at 9:41
  • I know exactly what you mean.
    – innaM
    Aug 13, 2009 at 9:44
11

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
1
  • 1
    +1. Excellent. I wasn't aware of this tool. I'd prefer this too to editing the file directly.
    – user4358
    Aug 12, 2009 at 10:38
8

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

1
  • In Ubuntu 12.10 there isn´t ~/.local/share/applications/defaults.list I had to edit ~/.local/share/applications/mimeapps.list
    – rodvlopes
    Jul 18, 2013 at 13:10

You must log in to answer this question.

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