Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   file.1p    ( 1 )

определить тип файла (determine file type)

Расширенное описание (Extended description)

A file specified as an option-argument to the -m or -M options shall contain one position-sensitive test per line, which shall be applied to the file. If the test succeeds, the message field of the line shall be printed and no further tests shall be applied, with the exception that tests on immediately following lines beginning with a single '>' character shall be applied.

Each line shall be composed of the following four <tab>-separated fields. (Implementations may allow any combination of one or more white-space characters other than <newline> to act as field separators.)

offset An unsigned number (optionally preceded by a single '>' character) specifying the offset, in bytes, of the value in the file that is to be compared against the value field of the line. If the file is shorter than the specified offset, the test shall fail.

If the offset begins with the character '>', the test contained in the line shall not be applied to the file unless the test on the last line for which the offset did not begin with a '>' was successful. By default, the offset shall be interpreted as an unsigned decimal number. With a leading 0x or 0X, the offset shall be interpreted as a hexadecimal number; otherwise, with a leading 0, the offset shall be interpreted as an octal number.

type The type of the value in the file to be tested. The type shall consist of the type specification characters d, s, and u, specifying signed decimal, string, and unsigned decimal, respectively.

The type string shall be interpreted as the bytes from the file starting at the specified offset and including the same number of bytes specified by the value field. If insufficient bytes remain in the file past the offset to match the value field, the test shall fail.

The type specification characters d and u can be followed by an optional unsigned decimal integer that specifies the number of bytes represented by the type. The type specification characters d and u can be followed by an optional C, S, I, or L, indicating that the value is of type char, short, int, or long, respectively.

The default number of bytes represented by the type specifiers d, f, and u shall correspond to their respective C-language types as follows. If the system claims conformance to the C-Language Development Utilities option, those specifiers shall correspond to the default sizes used in the c99 utility. Otherwise, the default sizes shall be implementation-defined.

For the type specifier characters d and u, the default number of bytes shall correspond to the size of a basic integer type of the implementation. For these specifier characters, the implementation shall support values of the optional number of bytes to be converted corresponding to the number of bytes in the C-language types char, short, int, or long. These numbers can also be specified by an application as the characters C, S, I, and L, respectively. The byte order used when interpreting numeric values is implementation-defined, but shall correspond to the order in which a constant of the corresponding type is stored in memory on the system.

All type specifiers, except for s, can be followed by a mask specifier of the form &number. The mask value shall be AND'ed with the value of the input file before the comparison with the value field of the line is made. By default, the mask shall be interpreted as an unsigned decimal number. With a leading 0x or 0X, the mask shall be interpreted as an unsigned hexadecimal number; otherwise, with a leading 0, the mask shall be interpreted as an unsigned octal number.

The strings byte, short, long, and string shall also be supported as type fields, being interpreted as dC, dS, dL, and s, respectively.

value The value to be compared with the value from the file.

If the specifier from the type field is s or string, then interpret the value as a string. Otherwise, interpret it as a number. If the value is a string, then the test shall succeed only when a string value exactly matches the bytes from the file.

If the value is a string, it can contain the following sequences:

\character The <backslash>-escape sequences as specified in the Base Definitions volume of POSIX.1‐2017, Table 5-1, Escape Sequences and Associated Actions ('\\', '\a', '\b', '\f', '\n', '\r', '\t', '\v'). In addition, the escape sequence '\ ' (the <backslash> character followed by a <space> character) shall be recognized to represent a <space> character. The results of using any other character, other than an octal digit, following the <backslash> are unspecified.

\octal Octal sequences that can be used to represent characters with specific coded values. An octal sequence shall consist of a <backslash> followed by the longest sequence of one, two, or three octal-digit characters (01234567).

By default, any value that is not a string shall be interpreted as a signed decimal number. Any such value, with a leading 0x or 0X, shall be interpreted as an unsigned hexadecimal number; otherwise, with a leading zero, the value shall be interpreted as an unsigned octal number.

If the value is not a string, it can be preceded by a character indicating the comparison to be performed. Permissible characters and the comparisons they specify are as follows:

= The test shall succeed if the value from the file equals the value field.

< The test shall succeed if the value from the file is less than the value field.

> The test shall succeed if the value from the file is greater than the value field.

& The test shall succeed if all of the set bits in the value field are set in the value from the file.

^ The test shall succeed if at least one of the set bits in the value field is not set in the value from the file.

x The test shall succeed if the file is large enough to contain a value of the type specified starting at the offset specified.

message The message to be printed if the test succeeds. The message shall be interpreted using the notation for the printf formatting specification; see printf. If the value field was a string, then the value from the file shall be the argument for the printf formatting specification; otherwise, the value from the file shall be the argument.