[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Files Reference


magic File Format

Purpose

Defines file types.

Description

The /etc/magic file is used by commands such as the following to determine the type of a given file:

Entering the following command would result in a printed message describing the file type of the FileName parameter:

file FileName 

If FileName contains a byte pattern corresponding to an executable file, the pattern would match a stanza in the /etc/magic file and the executable message would be displayed. If the FileName is a data file, a data message is displayed, and so on.

The fields of the magic file are as follows:

  1. Byte offset
  2. Value type
  3. Optional relational operator ("=" by default) and value to match (numeric or string constant)
  4. String to be printed

Numeric values may be decimal, octal, or hexadecimal. Strings can be entered as hexadecimal values by preceding them with '0x'.

The last string can have one printf format specification.

The > (greater than) symbol in occasional column 1s is magic; it forces commands to continue scanning and matching additional lines. The first line not marked with the > sign terminates the search.

Examples

0 short 2345 this is a dummy type file

0 long 0x1234 this is a different dummy type file

>12 long >0 another possible type

0 short 7895 last type of file

Related Information

The file command, more or page command.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]