unixfile-typemagic-numbers

How to get magic number of a binary file


There is a magic number associated with each binary file , does anyone know how to retrieve this information from the file?


Solution

  • Use libmagic from the file package to try and sniff out the type of file if that's your goal.

    There are no general "magic" numbers in binary files on unix, though different formats might define their own. The above library knows about many of those and also use various other heuristics to try and figure out the format/type of file.