How (exactly) does a utility like the UNIX filecommand guess the file type?
file
Are there any source codes?
It uses various heuristics, mainly signatures, which are described in the configuration file.
man -s 5 magic
will provide a file format.
He looks at the magic number in the first octets (2-4?) Of the file.
This is quite interesting here :)