From https://linux.die.net/man/1/file:The magic tests are used to check for files with data in particular fixed formats. The canonical example of this is a binary executable (compiled program) a.out file, whose format is defined in #include <a.out.h>  and possibly #include <exec.h> in the standard include directory. These files have a 'magic number' stored in a particular place near the beginning of the file that tells the UNIX operating system that the file is a binary executable, and which of several types thereof. The concept of a 'magic' has been applied by extension to data files. Any file with some invariant identifier at a small fixed offset into the file can usually be described in this way. The information identifying these files is read from the compiled magic file /usr/share/misc/magic.mgc, or the files in the directory /usr/share/misc/magic if the compiled file does not exist. In addition, if $HOME/.magic.mgc or $HOME/.magic exists, it will be used in preference to the system magic files. If /etc/magic exists, it will be used together with other magic files. Fair enough. So if, by coincidence, a text file happens to contain a 'magic number' specific to, for example, an mp4 video at an appropriate offset Will double-clicking such a text file result in a video player being launched instead of a text editor?
Unix decides about the type of a file looking for magic files at fixed offsets. How can it do so reliably?
file types