Linux File Magic Number

Linux File Magic Number

  • file <file_name>
  • magic numbers are usually stored in (linux) /usr/share/file/magic
  • also File Signatures, Magic Bytes
  • A magic number is a numeric or string constant that indicates the file type.
  • This number is in the first 512 bytes of the file.
    • Originally, this term was used for a specific set of 2-byte identifiers at the beginnings of files, but since any binary sequence can be regarded as a number, any feature of a file format which uniquely distinguishes it can be used for identification
  • By default the localized magic file /usr/lib/locale/locale/LC_MESSAGES/magic is used to identify files that have a magic number.
    • If a localized magic file does not exist, the /etc/magic file is utilized.

      get magic number of file

  • xxd image.png | head

reference