From the wiki entry,
Linux-based GUIs, such as KDE and GNOME, support MIME type-based associations. For example, the MIME type text/plain would be associated with a text editor.
Also, thisthis answer has more details.
File manager often use some combination of option a and b (e.g. look at the file extension first, if it's not known (or the file does not have an extension), look at the contents).
A file's type is not stored as metadata on common linux file systems.
From thisthis answer, I see the below information.
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.