How to get magic number of a binary file

cppb picture cppb · Jan 27, 2010 · Viewed 23.4k times · Source

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

Answer

rytis picture rytis · Jan 27, 2010
file <file_name>

magic numbers are usually stored in (linux):

/usr/share/file/magic

also check this link, someone was trying to use libmagic to get the information in C program, might be useful if you're writing something yourself.