MAGIC(5) COMMAND REFERENCE MAGIC(5)
NAME
magic - magic number file
DESCRIPTION
The magic file /usr/lib/magic contains information about
certain kinds of special files that exist in the system,
like object code files, compacted files, and archive files.
The utility file(1) uses the magic file to print information
about files. The subroutine notmagic(3c) uses the magic file
to determine if a file is a special type of file, not
suitable for printing on a terminal.
The magic file contains three types of lines. Lines
beginning with the character '#' are comments and are
ignored. Lines beginning with '0' are considered to be
magic number specification lines. If a line begins with a
'>', it is a continuation of the previous line and contains
information about following bytes.
The format of a specification line is:
0 type number description
All fields are separated by tabs. The type may be one of
byte, short, long, or string. Short numbers are interpreted
as unsigned short. If the magic number is not a string, it
may be an octal, hex, or decimal number. Octal numbers are
specified by beginning them with a '0'. Hex numbers must
begin with '0x'. Decimal numbers do not begin with '0' or
'0x'. The description is a string that describes the type of
file the magic number describes. It may contain one printf
style specifier (such as '%d') which file will replace by
the value of the magic number.
The following are examples of magic number specification
lines. The first line describes a compacted text file (see
compact(1) ), and the second describes a long format archive
file (see ar(5) ).
0 short 017777 Compacted text
0 string !<ARCH> ASCII archive (long format)
The format for a continuation line is:
>offset type op description
Again, fields are separated by tabs. The offset is the
number of bits that should be checked in the next field,
whose size is specified by the type field. The op is one of
'=', '>', or '<' followed by a number, the character 'x', or
a string. If the op is '>' followed by a number, the
corresponding data from the file must be a number that is
Printed 3/13/89 1
MAGIC(5) COMMAND REFERENCE MAGIC(5)
greater than the number given after the '>'. The characters
'<' and '=' are similar in function and mean 'less than' and
'equal to'. The character 'x' means that any number will
match. If the type field is ``string'', the op field is a
string to be matched. The special string ``.*'' matches any
string. This is useful for printing null-terminated strings
found at a known place in the file. The description field
is as before, except that a '%' specifier is replaced by the
value compared against op field.
The following lines show the description for an old style
executable object file.
0 short 0407 Old executable
>16 long >0 not stripped
The '>16' in the second line implies that the next value to
be checked starts at the 16th byte in the file. The '>0' in
the op field specifies that the file matches the description
("not stripped") if the value is greater than 0.
This is the description for a file which contains the magic
number 0177512 followed by a null terminated string which is
the file description.
0 long 0177512 Described file
>4 string .* -- %s
FILES
/usr/lib/magic The magic number file
CAVEATS
Most software that uses the magic file will not check the
format of the file very carefully. See the manual page for
file(1). This utility has the ability to check the format.
The programs vi, ex, e, edit, and view can only handle 300
magic numbers of type long and/or short.
SEE ALSO
ex(1), file(1), more(1), and notmagic(3c).
Printed 3/13/89 2
%%index%%
na:264,77;
de:341,3038;3715,1310;
fi:5025,121;
ca:5146,571;
se:5717,184;
%%index%%000000000106