Forget about the concept of "file extensions" that thing is completely made up and useless. For example somebody could rename a music file on your system to garbage.gbr and since windows interprets extensions literally as file types it wouldn't even know that the file was a music file.
In Ubuntu on the other hand, you can name a file whatever you wish. You don't even have to choose an extension if you don't feel like it. Ubuntu will read the MIME type of the file and understand what type it is. Based on the file type it will associate it to the appropriate program to open it. You still have all the control you need. You can change the default program associated with a MIME type in several ways.
To change default program association of a file type, just right click on a file with that type and choose Properties and go to Open With tab.
Now that being said, I should mention that extensions are not completely useless in Ubuntu. They still provide a standard way to tag a file for easy identification of its type -- but they don't set the file type. The only exception to this is when saving a file in some applications that support saving in several different formats. When you provide a file name in those application it can read the extension you provided and based on that decides how to create and save your new file with the correct mime type. For example if you open a JPEG file in GIMP and then choose save as ... and enter image.png, GIMP opens the PNG file dialogue and lets you save the file with PNG MIME Type.
There are two ways a MIME type and a .desktop
file are associated.
Method 1
The first way is through *.list
MIME config files (many exist on the system, see below). For example, a typical entry in ~/.local/share/applications/mimeapps.list
might be:
[Default Applications]
application/x-bittorrent=transmission.desktop;deluge.desktop
This means that the preferred application is transmission
, if it cannot be found, then the second choice is deluge
.
Method 2
The second way is through the .desktop
file itself. The application advertises which MIME types it can open. For example, in transmission-gtk.desktop
, we have the following line
MimeType=application/x-bittorrent;x-scheme-handler/magnet;
which indicates that this program can handle those two MIME types.
Which Application To Use?
The association between MIME types and Applications is defined by the freedesktop.org
standards. Here are the steps taken when determining which application (i.e. which .desktop
file) to launch for a given MIME type.
Step 1: Look for an association in the MIME config files. The lookup order is as follows:
$XDG_CONFIG_HOME/$desktop-mimeapps.list
$XDG_CONFIG_HOME/mimeapps.list
$XDG_CONFIG_DIRS/$desktop-mimeapps.list
$XDG_CONFIG_DIRS/mimeapps.list
$XDG_DATA_HOME/applications/$desktop-mimeapps.list
$XDG_DATA_HOME/applications/mimeapps.list
$XDG_DATA_DIRS/applications/$desktop-mimeapps.list
$XDG_DATA_DIRS/applications/mimeapps.list
Step 2: Once all levels have been checked, if no entry could be found, the implementations can pick any of the .desktop
files associated with the MIME type, taking into account added and removed associations (which exist in the MIME config files).
Although you do not have any MIME config files, the reason that transmission
is being used is because of Step 2 as defined by the standard. Check your transmission-gtk.desktop
file to see whether it advertises its ability to open torrents.
I suggest reading the linked document for a full understanding.
Best Answer
Via "magic"
http://linux.die.net/man/5/magic
http://linux.die.net/man/1/file