How does Ubuntu or any other Linux systems store file associations?
Is there some /etc/asscociations file or something?
I know that I can right click on file and change it via "open with", but I'm just curious to know how it's stored internally.
|
How does Ubuntu or any other Linux systems store file associations? Is there some I know that I can right click on file and change it via "open with", but I'm just curious to know how it's stored internally. |
||||
|
|
|
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 For example, GIMP has the following .desktop file:
See the 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 |
|||||||||||||||||||||
|
|
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:
|
|||||||||||||
|
|
I found that on my system (Debian Jessie) there's also a I was able to remove the line from |
|||||||||||||
|
|
Create a file
then edit the file
I found out the mime type of Truecrypt by following running this command:
|
|||||
|
|
I was able to set an association like this:
You can also remove associations and do other things: I did not need to run |
|||
|
|
|
I found this link concerning default association, it might be helpful.
https://wiki.archlinux.org/index.php/Default_Applications
per user association:
syntax is as follow:
[Added Associations] section is used to specify preferred (default) applications in decreasing preference. which means desktopfile1 is the most preferred and desktopfileN is least preferred. |
|||||||||||||
|
|
Freedesktop.org (previously called the X Desktop Group, thus the "XDG" abbreviation) is the group currently driving X standards like this (learn more at Wikipedia). warvariuc's answer already mentions xdg-mime usage like:
After lots of playing with image editors and viewers, I ended up with different viewers for different image types with almost no consistency, especially among the rarer image types. I took the above command and assigned it to each of the MIME types controlled by the image viewers and then created a new
This examines the (If you want to test this before running it live, change This technique should work for anything you want to reclaim for a target app. You don't even need to create a new |
|||
|
|
|
Others have mentioned this file, but none have explained it's location precisely. The freedesktop.org standard says at https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.html :
and then the default values for those environment variables is given at https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.6.html :
Older versions of Ubuntu may not check Commands like:
will automatically edit those files. |
||||
|
|
|
For all users:
Each user has a config file for overriding these defaults:
see also https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.1.html for places that might be used for overriding defauts. You must know the mime-type of the file you want to change it's association. Also all associations can be handled-changed in command line using:
|
|||
|
|