A file doesn't tell the OS its file format, with one exception:
If an executable file starts with a so-called shebang line, like
`##! /usr/bin/perl`perl then this line tells the Linux kernel that it should be started with /usr/bin/perl (that is, instead of executing this file, it should execute usr/bin/perl and give this file as argument). This of course only works with file formats which ignore (or understand) such a shebang line.
Other than that, the Operatingoperating system as such knows nothing about file types. However many programs which allow opening other files have their own mechanism to decide which program to use for opening which file. That can be a list inside the program itself (Firefox for example maintains such a list), or the program can delegate it to the desktop environment (of which there are several for Linux).
Usually, those mechanisms only consider the filename to decide what type the file is; an exception are email clients and web browsers, where usually the type of the file is explicitly given by the server/stated in the mail.
The mechanism is usually two-step:
- First, from the file name or supplied information, determine the MIME type of the file (the MIME type is a standardized, but extensible list of file types).
- Second, from the MIME type, determine which program to execute, usually through a sort of registry maintained either by the program itself or by the desktop environment the program was written for.