Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ magic(4) — Motorola System V 88k Release 4 Version 4.3

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

file(1)

pfmt(3C)

magic(4)  —  FILE FORMATS

NAME

magic − file command’s magic number file

DESCRIPTION

The file command identifies the type of a file by using, among other tests, a test for whether the file begins with a certain magic number.  The file /etc/magic specifies the magic numbers that the file command will test for, the message to print if a particular magic number is found, and additional information to extract from the file. 

Each line of the file specifies a test to be performed.  A test compares the data starting at a particular offset in the file with a 1-byte, 2-byte, or 4-byte numeric value or a string.  If the test succeeds, a message is printed.  The line consists of the following fields, with optional fields enclosed in square brackets:

byte_offset  value_type  value  message_id  default_string

The fields are separated by white space (blanks or tabs). 

If a line begins with the character > in column 1, it forces the file command to continue scanning and matching additional lines.  The first line that does not begin with > terminates the search. 

The fields for a line are described below. 

byte_offset
A number specifying the offset, in bytes, into the file of the data which is to be tested.

value_type
The type of the data to be tested. The possible values are:

byte A one-byte value

short A two-byte value

long A four-byte value

string A string of bytes. 

The types byte, short, and long may be followed by a mask specifier of the form &number.  If a mask specifier is given, the value is AND’ed with the number before any comparisons are done.  The number is specified in C form.  For example, 13 is decimal, 013 is octal, and 0x13 is hexadecimal. 

value The value to be compared with the value from the file.  If the type is numeric, this value is specified in C form, as described above.  If it is a string, it is specified as a C string with the usual escapes permitted (for instance, \n for NEWLINE). 

The value may be preceded by a character indicating the operation to be performed.  It may be one of the following:

= specifies that the value from the file must equal the specified value

< specifies that the value from the file must be less than the specified value

> specifies that the value from the file must be greater than the specified value

& specifies that all the bits in the specified value must be set in the value from the file,

^ specifies that at least one of the bits in the specified value must not be set in the value from the file

x specifies that any value will match

If the character is omitted, it is assumed to be ‘=’. 

For string values, the byte string from the file must match the specified byte string.  The byte string from the file which is matched is the same length as the specified byte string. 

message_id
An identifier for a string in the messages database that will be printed if there is a match. The format of the message_id is described on the pfmt(3C) manual page. 

default_string
A string that is printed if message_id is not found in the messages database. 

FILES

/etc/magic

SEE ALSO

file(1), pfmt(3C)

  —  Essential Utilities

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026