4 .\" install as magic.4 on USG, magic.5 on V7 or Berkeley systems.
7 .Dt MAGIC 5 "Public Domain"
11 .Nd file command's magic number file
13 This manual page documents the format of the magic file as
16 command, version 3.41.
19 command identifies the type of a file using,
21 a test for whether the file begins with a certain
24 .Pa /usr/share/misc/magic
25 specifies what magic numbers are to be tested for,
26 what message to print if a particular magic number is found,
27 and additional information to extract from the file.
29 Each line of the file specifies a test to be performed.
30 A test compares the data starting at a particular offset
31 in the file with a 1-byte, 2-byte, or 4-byte numeric value or
33 If the test succeeds, a message is printed.
34 The line consists of the following fields:
35 .Bl -tag -width indent
37 A number specifying the offset, in bytes, into the file of the data
38 which is to be tested.
40 The type of the data to be tested.
41 The possible values are:
42 .Bl -tag -width indent
46 A two-byte value (on most systems) in this machine's native byte order.
48 A four-byte value (on most systems) in this machine's native byte order.
51 The string type specification can be optionally followed
55 flag compacts whitespace in the target, which must contain
56 at least one whitespace character.
57 If the magic has "n" consecutive blanks, the target needs
58 at least "n" consecutive blanks to match.
61 flag treats every blank in the target as an optional blank.
64 flag, specifies case insensitive matching: lowercase characters
65 in the magic match both lower and upper case characters in the
66 targer, whereas upper case characters in the magic, only much
67 uppercase characters in the target.
69 A four-byte value interpreted as a
73 A four-byte value interpreted as a
75 date, but interpreted as
76 local time rather than UTC.
78 A two-byte value (on most systems) in big-endian byte order.
80 A four-byte value (on most systems) in big-endian byte order.
82 A four-byte value (on most systems) in big-endian byte order,
87 A two-byte value (on most systems) in little-endian byte order.
89 A four-byte value (on most systems) in little-endian byte order.
91 A four-byte value (on most systems) in little-endian byte order,
96 A four-byte value (on most systems) in little-endian byte order,
99 date, but interpreted as local time rather
104 The numeric types may optionally be followed by
107 to specify that the value is to be AND'ed with the
108 numeric value before any comparisons are done. Prepending a
110 to the type indicates that ordered comparisons should be unsigned.
111 .Bl -tag -width indent
113 The value to be compared with the value from the file. If the type is
115 is specified in C form; if it is a string, it is specified as a C string
116 with the usual escapes permitted (e.g. \en for new-line).
119 may be preceded by a character indicating the operation to be performed.
122 to specify that the value from the file must equal the specified value,
124 to specify that the value from the file must be less than the specified
127 to specify that the value from the file must be greater than the specified
130 to specify that the value from the file must have set all of the bits
131 that are set in the specified value,
133 to specify that the value from the file must have clear any of the bits
134 that are set in the specified value, or
136 to specify that any value will match.
137 If the character is omitted,
141 Numeric values are specified in C form; e.g.\&
149 For string values, the byte string from the
150 file must match the specified byte string.
158 can be applied to strings.
159 The length used for matching is that of the string argument
160 in the magic file. This means that a line can match any string, and
161 then presumably print that string, by doing
163 (because all strings are greater than the null string).
165 The message to be printed if the comparison succeeds. If the string
168 format specification, the value from the file (with any specified masking
169 performed) is printed using the message as the format string.
172 Some file formats contain additional information which is to be printed
173 along with the file type. A line which begins with the character
175 indicates additional tests and messages to be printed. The number of
177 on the line indicates the level of the test; a line with no
179 at the beginning is considered to be at level 0.
182 is under the control of the line at level
184 most closely preceding it in the magic file.
185 If the test on a line at level
187 succeeds, the tests specified in all the subsequent lines at level
189 are performed, and the messages printed if the tests succeed. The next
193 If the first character following the last
197 then the string after the parenthesis is interpreted as an indirect offset.
198 That means that the number after the parenthesis is used as an offset in
200 The value at that offset is read, and is used again as an offset
202 Indirect offsets are of the form:
203 .Em (x[.[bslBSL]][+-][y]) .
206 is used as an offset in the file.
207 A byte, short or long is read at that offset
211 The capitalized types interpret the number as a big endian value, whereas
212 a small letter versions interpret the number as a little endian value.
213 To that number the value of
215 is added and the result is used as an offset in the file.
217 if one is not specified is long.
219 Sometimes you do not know the exact offset as this depends on the length of
221 You can specify an offset relative to the end of the
222 last uplevel field (of course this may only be done for sublevel tests, i.e.\&
225 Such a relative offset is specified using
227 as a prefix to the offset.
240 are system-dependent; perhaps they should be specified as a number
241 of bytes (2B, 4B, etc),
242 since the files being recognized typically come from
243 a system on which the lengths are invariant.
245 There is (currently) no support for specified-endian data to be used in
250 .\" From: guy@sun.uucp (Guy Harris)
251 .\" Newsgroups: net.bugs.usg
252 .\" Subject: /etc/magic's format isn't well documented
253 .\" Message-ID: <2752@sun.uucp>
254 .\" Date: 3 Sep 85 08:19:07 GMT
255 .\" Organization: Sun Microsystems, Inc.
258 .\" Here's a manual page for the format accepted by the "file" made by adding
259 .\" the changes I posted to the S5R2 version.
261 .\" Modified for Ian Darwin's version of the file command.
262 .\" @(#)$Id: magic.man,v 1.21 2003/02/27 20:47:46 christos Exp $