Where are file associations stored?
The file manager (Nautilus, by default) uses the MIME type of a file to determine which program to open it with.
When an application is installed, it can specify what MIME types it can open and the command to use to open the files in the .desktop file which is placed in /usr/share/applications
. This is the file used for menus, desktop shortcuts, etc.
For example, GIMP has the following .desktop file:
[Desktop Entry]
Version=1.0
Type=Application
Name=GNU Image Manipulation Program
GenericName=Image Editor
Comment=Create images and edit photographs
Exec=gimp-2.7 %U
TryExec=gimp-2.7
Icon=gimp
Terminal=false
Categories=Graphics;2DGraphics;RasterGraphics;GTK;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=GIMP
X-GNOME-Bugzilla-Component=General
X-GNOME-Bugzilla-Version=2.7.2
X-GNOME-Bugzilla-OtherBinaries=gimp-2.7
StartupNotify=true
MimeType=application/postscript;application/pdf;image/bmp;image/g3fax;image/gif;image/x-fits;image/pcx;image/x-portable-anymap;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-psd;image/x-sgi;image/x-tga;image/x-xbitmap;image/x-xwindowdump;image/x-xcf;image/x-compressed-xcf;image/tiff;image/jpeg;image/x-psp;image/png;image/x-icon;image/x-xpixmap;image/svg+xml;application/pdf;image/x-wmf;image/jp2;image/jpeg2000;image/jpx;image/x-xcursor;
See the MimeType
field - this lists the supported MIME types.The Exec
field tells the system to use the command gimp-2.7 %U
, replacing '%U' with the files to open. (Note GIMP 2.7 is a version I have installed from a PPA, so is higher than the current version in the Ubuntu repositories).
When the application package is installed, the system extracts this MIME type data into a more easily accessible database because looking in each .desktop file would take too long if it was done every time a file was opened.
This tells the system what applications can be used for that MIME type and provides the applications in the 'Open With' list. The default is defined elsewhere. The file /usr/share/applications/defaults.list
provides the information for the system defaults. Unless you choose otherwise, these are the applications used when you 'Open' a file.
To supplement dv3500ea's excellent answer, I would like to add some information about what happens when you change your associations.
While the defaults.list (which you can find by typing 'locate defaults.list') provides the list of applications that are associated with each MIME type, any customizations that you make are stored in your home directory, in ~/.local/share/applications/mimeapps.list. So if you add or remove associations, or change the default association, this file is updated.
The GNOME Desktop System Administration Guide at http://library.gnome.org/admin/system-admin-guide/stable/ does not appear to discuss mimeapps.list, but I found the following description on http://live.gnome.org/SysAdminGuideUpdate:
mimeapps.list is located in $XDG_DATA_DIRS/applications. Its purpose is to add or remove mime associations from applications. nautilus writes ~/.local/share/applications/mimeapps.list when the user makes changes in the "Open With" dialog.
I found that on my system (Debian Jessie) there's also a ~/.config/mimeapps.list
that had an association I accidentally created to open a specific file type with gedit. None of the standard ways of correcting this (default application settings, Thunar's open with property) reflected this, but gedit was the default application.
I was able to remove the line from ~/.config/mimeapps.list
and now the correct application opens the file.