1 .TH MAGIC __FSECTION__ "Public Domain"
2 .\" install as magic.4 on USG, magic.5 on V7 or Berkeley systems.
4 magic \- file command's magic number file
6 This manual page documents the format of the magic file as
8 .BR file (__CSECTION__)
9 command, version __VERSION__. The
11 command identifies the type of a file using,
13 a test for whether the file begins with a certain
17 specifies what magic numbers are to be tested for,
18 what message to print if a particular magic number is found,
19 and additional information to extract from the file.
21 Each line of the file specifies a test to be performed.
22 A test compares the data starting at a particular offset
23 in the file with a 1-byte, 2-byte, or 4-byte numeric value or
24 a string. If the test succeeds, a message is printed.
25 The line consists of the following fields:
26 .IP offset \w'message'u+2n
27 A number specifying the offset, in bytes, into the file of the data
28 which is to be tested.
30 The type of the data to be tested. The possible values are:
32 .IP byte \w'message'u+2n
35 A two-byte value (on most systems) in this machine's native byte order.
37 A four-byte value (on most systems) in this machine's native byte order.
39 A string of bytes. The string type specification can be optionally followed
40 by /[Bbc]*. The ``B'' flag compacts whitespace in the target, which must
41 contain at least one whitespace character. If the magic has "n" consecutive
42 blanks, the target needs at least "n" consecutive blanks to match. The ``b''
43 flag treats every blank in the target as an optional blank. Finally the ``c''
44 flag, specifies case insensitive matching: lowercase characters in the magic
45 match both lower and upper case characters in the targer, whereas upper case
46 characters in the magic, only much uppercase characters in the target.
48 A four-byte value interpreted as a UNIX date.
50 A four-byte value interpreted as a UNIX-style date, but interpreted as
51 local time rather than UTC.
53 A two-byte value (on most systems) in big-endian byte order.
55 A four-byte value (on most systems) in big-endian byte order.
57 A four-byte value (on most systems) in big-endian byte order,
58 interpreted as a unix date.
60 A two-byte value (on most systems) in little-endian byte order.
62 A four-byte value (on most systems) in little-endian byte order.
64 A four-byte value (on most systems) in little-endian byte order,
65 interpreted as a UNIX date.
67 A four-byte value (on most systems) in little-endian byte order,
68 interpreted as a UNIX-style date, but interpreted as local time rather
72 The numeric types may optionally be followed by
75 to specify that the value is to be AND'ed with the
76 numeric value before any comparisons are done. Prepending a
78 to the type indicates that ordered comparisons should be unsigned.
80 The value to be compared with the value from the file. If the type is
82 is specified in C form; if it is a string, it is specified as a C string
83 with the usual escapes permitted (e.g. \en for new-line).
86 may be preceded by a character indicating the operation to be performed.
89 to specify that the value from the file must equal the specified value,
91 to specify that the value from the file must be less than the specified
94 to specify that the value from the file must be greater than the specified
97 to specify that the value from the file must have set all of the bits
98 that are set in the specified value,
100 to specify that the value from the file must have clear any of the bits
101 that are set in the specified value, or
103 to specify that any value will match. If the character is omitted,
107 Numeric values are specified in C form; e.g.
115 For string values, the byte string from the
116 file must match the specified byte string.
124 can be applied to strings.
125 The length used for matching is that of the string argument
126 in the magic file. This means that a line can match any string, and
127 then presumably print that string, by doing
129 (because all strings are greater than the null string).
131 The message to be printed if the comparison succeeds. If the string
134 format specification, the value from the file (with any specified masking
135 performed) is printed using the message as the format string.
137 Some file formats contain additional information which is to be printed
138 along with the file type. A line which begins with the character
140 indicates additional tests and messages to be printed. The number of
142 on the line indicates the level of the test; a line with no
144 at the beginning is considered to be at level 0.
147 is under the control of the line at level
149 most closely preceding it in the magic file.
150 If the test on a line at level
152 succeeds, the tests specified in all the subsequent lines at level
154 are performed, and the messages printed if the tests succeed. The next
158 If the first character following the last
162 then the string after the parenthesis is interpreted as an indirect offset.
163 That means that the number after the parenthesis is used as an offset in
164 the file. The value at that offset is read, and is used again as an offset
165 in the file. Indirect offsets are of the form:
166 .BI (( x [.[bslBSL]][+-][ y ]).
169 is used as an offset in the file. A byte, short or long is read at that offset
172 type specifier. The capitalized types interpret the number as a big endian
173 value, whereas the small letter versions interpet the number as a little
174 endian value. To that number the value of
176 is added and the result is used as an offset in the file. The default type
177 if one is not specified is long.
179 Sometimes you do not know the exact offset as this depends on the length of
180 preceding fields. You can specify an offset relative to the end of the
181 last uplevel field (of course this may only be done for sublevel tests, i.e.
184 ). Such a relative offset is specified using
186 as a prefix to the offset.
199 are system-dependent; perhaps they should be specified as a number
200 of bytes (2B, 4B, etc),
201 since the files being recognized typically come from
202 a system on which the lengths are invariant.
204 There is (currently) no support for specified-endian data to be used in
207 .BR file (__CSECTION__)
208 \- the command that reads this file.
210 .\" From: guy@sun.uucp (Guy Harris)
211 .\" Newsgroups: net.bugs.usg
212 .\" Subject: /etc/magic's format isn't well documented
213 .\" Message-ID: \*[Lt]2752@sun.uucp\*[Gt]
214 .\" Date: 3 Sep 85 08:19:07 GMT
215 .\" Organization: Sun Microsystems, Inc.
218 .\" Here's a manual page for the format accepted by the "file" made by adding
219 .\" the changes I posted to the S5R2 version.
221 .\" Modified for Ian Darwin's version of the file command.
222 .\" @(#)$Id: magic.man,v 1.19 2002/07/03 18:26:38 christos Exp $