Home » Questions » Computers [ Ask a new question ]

Ubuntu -- Change the default program used to open a type of file

Ubuntu -- Change the default program used to open a type of file

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

Asked by: Guest | Views: 120
Total answers/comments: 2
Guest [Entry]

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

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