1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
|
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
.TH "FILE" P 2003 POSIX
.\" file
.SH NAME
file \- determine file type
.SH SYNOPSIS
.LP
\fBfile\fP \fB[\fP\fB-dh\fP\fB][\fP\fB-M\fP \fIfile\fP\fB][\fP\fB-m\fP
\fIfile\fP\fB]\fP
\fIfile\fP \fB...
.br
.sp
file -i\fP \fB[\fP\fB-h\fP\fB]\fP \fIfile\fP \fB... \fP
\fB
.br
\fP
.SH DESCRIPTION
.LP
The \fIfile\fP utility shall perform a series of tests in sequence
on each specified \fIfile\fP in an attempt to classify
it:
.IP " 1." 4
If \fIfile\fP does not exist, cannot be read, or its file status could
not be determined, the output shall indicate that the
file was processed, but that its type could not be determined.
.LP
.IP " 2." 4
If the file is not a regular file, its file type shall be identified.
The file types directory, FIFO, socket, block special, and
character special shall be identified as such. Other implementation-defined
file types may also be identified. If \fIfile\fP is a
symbolic link, by default the link shall be resolved and \fIfile\fP
shall test the type of file referenced by the symbolic link.
(See the \fB-h\fP and \fB-i\fP options below.)
.LP
.IP " 3." 4
If the length of \fIfile\fP is zero, it shall be identified as an
empty file.
.LP
.IP " 4." 4
The \fIfile\fP utility shall examine an initial segment of \fIfile\fP
and shall make a guess at identifying its contents based
on position-sensitive tests. (The answer is not guaranteed to be correct;
see the \fB-d\fP, \fB-M\fP, and \fB-m\fP options
below.)
.LP
.IP " 5." 4
The \fIfile\fP utility shall examine \fIfile\fP and make a guess at
identifying its contents based on context-sensitive
default system tests. (The answer is not guaranteed to be correct.)
.LP
.IP " 6." 4
The file shall be identified as a data file.
.LP
.LP
If \fIfile\fP does not exist, cannot be read, or its file status could
not be determined, the output shall indicate that the
file was processed, but that its type could not be determined.
.LP
If \fIfile\fP is a symbolic link, by default the link shall be resolved
and \fIfile\fP shall test the type of file referenced
by the symbolic link.
.SH OPTIONS
.LP
The \fIfile\fP utility shall conform to the Base Definitions volume
of IEEE\ Std\ 1003.1-2001, Section 12.2, Utility Syntax Guidelines,
except that the order of the \fB-m\fP,
\fB-d\fP, and \fB-M\fP options shall be significant.
.LP
The following options shall be supported by the implementation:
.TP 7
\fB-d\fP
Apply any position-sensitive default system tests and context-sensitive
default system tests to the file. This is the default
if no \fB-M\fP or \fB-m\fP option is specified.
.TP 7
\fB-h\fP
When a symbolic link is encountered, identify the file as a symbolic
link. If \fB-h\fP is not specified and \fIfile\fP is a
symbolic link that refers to a nonexistent file, \fIfile\fP shall
identify the file as a symbolic link, as if \fB-h\fP had been
specified.
.TP 7
\fB-i\fP
If a file is a regular file, do not attempt to classify the type of
the file further, but identify the file as specified in the
STDOUT section.
.TP 7
\fB-M\ \fP \fIfile\fP
Specify the name of a file containing position-sensitive tests that
shall be applied to a file in order to classify it (see the
EXTENDED DESCRIPTION). No position-sensitive default system tests
nor context-sensitive default system tests shall be applied
unless the \fB-d\fP option is also specified.
.TP 7
\fB-m\ \fP \fIfile\fP
Specify the name of a file containing position-sensitive tests that
shall be applied to a file in order to classify it (see the
EXTENDED DESCRIPTION).
.sp
.LP
If the \fB-m\fP option is specified without specifying the \fB-d\fP
option or the \fB-M\fP option, position-sensitive default
system tests shall be applied after the position-sensitive tests specified
by the \fB-m\fP option. If the \fB-M\fP option is
specified with the \fB-d\fP option, the \fB-m\fP option, or both,
or the \fB-m\fP option is specified with the \fB-d\fP option,
the concatenation of the position-sensitive tests specified by these
options shall be applied in the order specified by the
appearance of these options. If a \fB-M\fP or \fB-m\fP \fIfile\fP
option-argument is \fB-\fP, the results are unspecified.
.SH OPERANDS
.LP
The following operand shall be supported:
.TP 7
\fIfile\fP
A pathname of a file to be tested.
.sp
.SH STDIN
.LP
Not used.
.SH INPUT FILES
.LP
The \fIfile\fP can be any file type.
.SH ENVIRONMENT VARIABLES
.LP
The following environment variables shall affect the execution of
\fIfile\fP:
.TP 7
\fILANG\fP
Provide a default value for the internationalization variables that
are unset or null. (See the Base Definitions volume of
IEEE\ Std\ 1003.1-2001, Section 8.2, Internationalization Variables
for
the precedence of internationalization variables used to determine
the values of locale categories.)
.TP 7
\fILC_ALL\fP
If set to a non-empty string value, override the values of all the
other internationalization variables.
.TP 7
\fILC_CTYPE\fP
Determine the locale for the interpretation of sequences of bytes
of text data as characters (for example, single-byte as
opposed to multi-byte characters in arguments and input files).
.TP 7
\fILC_MESSAGES\fP
Determine the locale that should be used to affect the format and
contents of diagnostic messages written to standard error and
informative messages written to standard output.
.TP 7
\fINLSPATH\fP
Determine the location of message catalogs for the processing of \fILC_MESSAGES
\&.\fP
.sp
.SH ASYNCHRONOUS EVENTS
.LP
Default.
.SH STDOUT
.LP
In the POSIX locale, the following format shall be used to identify
each operand, \fIfile\fP specified:
.sp
.RS
.nf
\fB"%s: %s\\n", <\fP\fIfile\fP\fB>, <\fP\fItype\fP\fB>
\fP
.fi
.RE
.LP
The values for <\fItype\fP> are unspecified, except that in the POSIX
locale, if \fIfile\fP is identified as one of the
types listed in the following table, <\fItype\fP> shall contain (but
is not limited to) the corresponding string, unless the
file is identified by a position-sensitive test specified by a \fB-M\fP
or \fB-m\fP option. Each space shown in the strings shall
be exactly one <space>.
.br
.sp
.ce 1
\fBTable: File Utility Output Strings\fP
.TS C
center; lw(40)1 lw(25)1 l.
T{
.na
\fBIf \fIfile\fP is:\fP
.ad
T} T{
.na
\fB<\fItype\fP> shall contain the string:\fP
.ad
T} \fBNotes\fP
T{
.na
Nonexistent
.ad
T} T{
.na
cannot open
.ad
T} \
T{
.na
Block special
.ad
T} T{
.na
block special
.ad
T} 1
T{
.na
Character special
.ad
T} T{
.na
character special
.ad
T} 1
T{
.na
Directory
.ad
T} T{
.na
directory
.ad
T} 1
T{
.na
FIFO
.ad
T} T{
.na
fifo
.ad
T} 1
T{
.na
Socket
.ad
T} T{
.na
socket
.ad
T} 1
T{
.na
Symbolic link
.ad
T} T{
.na
symbolic link to
.ad
T} 1
T{
.na
Regular file
.ad
T} T{
.na
regular file
.ad
T} 1,2
T{
.na
Empty regular file
.ad
T} T{
.na
empty
.ad
T} 3
T{
.na
Regular file that cannot be read
.ad
T} T{
.na
cannot open
.ad
T} 3
T{
.na
Executable binary
.ad
T} T{
.na
executable
.ad
T} 4,6
T{
.na
\fIar\fP archive library (see \fIar\fP)
.ad
T} T{
.na
archive
.ad
T} 4,6
T{
.na
Extended \fIcpio\fP format (see \fIpax\fP)
.ad
T} T{
.na
cpio archive
.ad
T} 4,6
T{
.na
Extended \fItar\fP format (see \fBustar\fP in \fIpax\fP)
.ad
T} T{
.na
tar archive
.ad
T} 4,6
T{
.na
Shell script
.ad
T} T{
.na
commands text
.ad
T} 5,6
T{
.na
C-language source
.ad
T} T{
.na
c program text
.ad
T} 5,6
T{
.na
FORTRAN source
.ad
T} T{
.na
fortran program text
.ad
T} 5,6
T{
.na
Regular file whose type cannot be determined
.ad
T} T{
.na
data
.ad
T} \
.TE
.TP 7
\fBNotes:\fP
.RS
.IP " 1." 4
This is a file type test.
.LP
.IP " 2." 4
This test is applied only if the \fB-i\fP option is specified.
.LP
.IP " 3." 4
This test is applied only if the \fB-i\fP option is not specified.
.LP
.IP " 4." 4
This is a position-sensitive default system test.
.LP
.IP " 5." 4
This is a context-sensitive default system test.
.LP
.IP " 6." 4
Position-sensitive default system tests and context-sensitive default
system tests are not applied if the \fB-M\fP option is
specified unless the \fB-d\fP option is also specified.
.LP
.RE
.sp
.LP
In the POSIX locale, if \fIfile\fP is identified as a symbolic link
(see the \fB-h\fP option), the following alternative
output format shall be used:
.sp
.RS
.nf
\fB"%s: %s %s\\n", <\fP\fIfile\fP\fB>, <\fP\fItype\fP\fB>, <\fP\fIcontents of link\fP\fB>"
\fP
.fi
.RE
.LP
If the file named by the \fIfile\fP operand does not exist, cannot
be read, or the type of the file named by the \fIfile\fP
operand cannot be determined, this shall not be considered an error
that affects the exit status.
.SH STDERR
.LP
The standard error shall be used only for diagnostic messages.
.SH OUTPUT FILES
.LP
None.
.SH EXTENDED DESCRIPTION
.LP
A file specified as an option-argument to the \fB-m\fP or \fB-M\fP
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 \fB'>'\fP character shall be
applied.
.LP
Each line shall be composed of the following four <blank>-separated
fields:
.TP 7
\fIoffset\fP
An unsigned number (optionally preceded by a single \fB'>'\fP character)
specifying the \fIoffset\fP, in bytes, of the
value in the file that is to be compared against the \fIvalue\fP field
of the line. If the file is shorter than the specified
offset, the test shall fail.
.LP
If the \fIoffset\fP begins with the character \fB'>'\fP , the test
contained in the line shall not be applied to the file
unless the test on the last line for which the \fIoffset\fP did not
begin with a \fB'>'\fP was successful. By default, the
\fIoffset\fP shall be interpreted as an unsigned decimal number. With
a leading 0x or 0X, the \fIoffset\fP shall be interpreted
as a hexadecimal number; otherwise, with a leading 0, the \fIoffset\fP
shall be interpreted as an octal number.
.TP 7
\fItype\fP
The type of the value in the file to be tested. The type shall consist
of the type specification characters \fBc\fP ,
\fBd\fP , \fBf\fP , \fBs\fP , and \fBu\fP , specifying character,
signed decimal, floating point, string, and unsigned
decimal, respectively.
.LP
The \fItype\fP string shall be interpreted as the bytes from the file
starting at the specified \fIoffset\fP and including the
same number of bytes specified by the \fIvalue\fP field. If insufficient
bytes remain in the file past the \fIoffset\fP to match
the \fIvalue\fP field, the test shall fail.
.LP
The type specification characters \fBd\fP , \fBf\fP , and \fBu\fP
can be followed by an optional unsigned decimal
integer that specifies the number of bytes represented by the type.
The type specification character \fBf\fP can be followed by
an optional \fBF\fP , \fBD\fP , or \fBL\fP , indicating that the value
is of type \fBfloat\fP, \fBdouble\fP, or \fBlong
double\fP, respectively. The type specification characters \fBd\fP
and \fBu\fP can be followed by an optional \fBC\fP ,
\fBS\fP , \fBI\fP , or \fBL\fP , indicating that the value is of type
\fBchar\fP, \fBshort\fP, \fBint\fP, or
\fBlong\fP, respectively.
.LP
The default number of bytes represented by the type specifiers \fBd\fP
, \fBf\fP , and \fBu\fP 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
\fIc99\fP utility.
Otherwise, the default sizes shall be implementation-defined.
.LP
For the type specifier characters \fBd\fP and \fBu\fP , 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 \fBchar\fP, \fBshort\fP, \fBint\fP,
or \fBlong\fP. These numbers can also be specified by an application
as the characters \fBC\fP , \fBS\fP , \fBI\fP , and
\fBL\fP , 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.
.LP
For the type specifier \fBf\fP , the default number of bytes shall
correspond to the number of bytes in the basic double
precision floating-point data type of the underlying implementation.
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 \fBfloat\fP, \fBdouble\fP, and \fBlong
double\fP. These numbers can also be specified by an application as
the characters \fBF\fP , \fBD\fP , and \fBL\fP ,
respectively.
.LP
All type specifiers, except for \fBs\fP , can be followed by a mask
specifier of the form &\fInumber\fP. The mask value
shall be AND'ed with the value of the input file before the comparison
with the \fIvalue\fP 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.
.LP
The strings \fBbyte\fP, \fBshort\fP, \fBlong\fP, and \fBstring\fP
shall also be supported as type fields, being interpreted
as \fBdC\fP , \fBdS\fP , \fBdL\fP , and \fBs\fP , respectively.
.TP 7
\fIvalue\fP
The \fIvalue\fP to be compared with the value from the file.
.LP
If the specifier from the type field is \fBs\fP or \fBstring\fP, 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.
.LP
If the \fIvalue\fP is a string, it can contain the following sequences:
.TP 7
\\\fIcharacter\fP
.RS
The backslash-escape sequences as specified in the Base Definitions
volume of IEEE\ Std\ 1003.1-2001, Table 5-1, Escape
Sequences and Associated Actions ( \fB'\\\\'\fP , \fB'\\a'\fP , \fB'\\b'\fP
, \fB'\\f'\fP , \fB'\\n'\fP , \fB'\\r'\fP ,
\fB'\\t'\fP , \fB'\\v'\fP ). The results of using any other character,
other than an octal digit, following the backslash are
unspecified.
.RE
.TP 7
\\\fIoctal\fP
.RS
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). If the size of a byte on the
system is greater than 9 bits, the valid escape sequence used to represent
a byte is implementation-defined.
.RE
.sp
.LP
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.
.LP
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:
.TP 7
\fB=\fP
.RS
The test shall succeed if the value from the file equals the \fIvalue\fP
field.
.RE
.TP 7
\fB<\fP
.RS
The test shall succeed if the value from the file is less than the
\fIvalue\fP field.
.RE
.TP 7
\fB>\fP
.RS
The test shall succeed if the value from the file is greater than
the \fIvalue\fP field.
.RE
.TP 7
\fB&\fP
.RS
The test shall succeed if all of the set bits in the \fIvalue\fP field
are set in the value from the file.
.RE
.TP 7
\fB^\fP
.RS
The test shall succeed if at least one of the set bits in the \fIvalue\fP
field is not set in the value from the file.
.RE
.TP 7
\fBx\fP
.RS
The test shall succeed if the file is large enough to contain a value
of the type specified starting at the offset
specified.
.RE
.sp
.TP 7
\fImessage\fP
The \fImessage\fP to be printed if the test succeeds. The \fImessage\fP
shall be interpreted using the notation for the \fIprintf\fP formatting
specification; see \fIprintf\fP() . If the
\fIvalue\fP field was a string, then the value from the file shall
be the argument for the \fIprintf\fP formatting specification; otherwise,
the value from the file shall be the
argument.
.sp
.SH EXIT STATUS
.LP
The following exit values shall be returned:
.TP 7
\ 0
Successful completion.
.TP 7
>0
An error occurred.
.sp
.SH CONSEQUENCES OF ERRORS
.LP
Default.
.LP
\fIThe following sections are informative.\fP
.SH APPLICATION USAGE
.LP
The \fIfile\fP utility can only be required to guess at many of the
file types because only exhaustive testing can determine
some types with certainty. For example, binary data on some implementations
might match the initial segment of an executable or a
\fItar\fP archive.
.LP
Note that the table indicates that the output contains the stated
string. Systems may add text before or after the string. For
executables, as an example, the machine architecture and various facts
about how the file was link-edited may be included. Note
also that on systems that recognize shell script files starting with
\fB"#!"\fP as executable files, these may be identified as
executable binary files rather than as shell scripts.
.SH EXAMPLES
.LP
Determine whether an argument is a binary executable file:
.sp
.RS
.nf
\fBfile "$1" | grep -Fq executable &&
printf "%s is executable.\\n" "$1"
\fP
.fi
.RE
.SH RATIONALE
.LP
The \fB-f\fP option was omitted because the same effect can (and should)
be obtained using the \fIxargs\fP utility.
.LP
Historical versions of the \fIfile\fP utility attempt to identify
the following types of files: symbolic link, directory,
character special, block special, socket, \fItar\fP archive, \fIcpio\fP
archive, SCCS archive, archive library, empty, \fIcompress\fP output,
\fIpack\fP output, binary data, C source, FORTRAN source, assembler
source, \fInroff\fP/ \fItroff\fP/ \fIeqn\fP/ \fItbl\fP source \fItroff\fP
output, shell script, C shell script, English text,
ASCII text, various executables, APL workspace, compiled terminfo
entries, and CURSES screen images. Only those types that are
reasonably well specified in POSIX or are directly related to POSIX
utilities are listed in the table.
.LP
Historical systems have used a "magic file" named \fB/etc/magic\fP
to help identify file types. Because it is generally
useful for users and scripts to be able to identify special file types,
the \fB-m\fP flag and a portable format for user-created
magic files has been specified. No requirement is made that an implementation
of \fIfile\fP use this method of identifying files,
only that users be permitted to add their own classifying tests.
.LP
In addition, three options have been added to historical practice.
The \fB-d\fP flag has been added to permit users to cause
their tests to follow any default system tests. The \fB-i\fP flag
has been added to permit users to test portably for regular
files in shell scripts. The \fB-M\fP flag has been added to permit
users to ignore any default system tests.
.LP
The IEEE\ Std\ 1003.1-2001 description of default system tests and
the interaction between the \fB-d\fP, \fB-M\fP, and
\fB-m\fP options did not clearly indicate that there were two types
of "default system tests". The "position-sensitive tests''
determine file types by looking for certain string or binary values
at specific offsets in the file being examined. These
position-sensitive tests were implemented in historical systems using
the magic file described above. Some of these tests are now
built into the \fIfile\fP utility itself on some implementations so
the output can provide more detail than can be provided by
magic files. For example, a magic file can easily identify a \fBcore\fP
file on most implementations, but cannot name the program
file that dropped the core. A magic file could produce output such
as:
.sp
.RS
.nf
\fB/home/dwc/core: ELF 32-bit MSB core file SPARC Version 1
\fP
.fi
.RE
.LP
but by building the test into the \fIfile\fP utility, you could get
output such as:
.sp
.RS
.nf
\fB/home/dwc/core: ELF 32-bit MSB core file SPARC Version 1, from 'testprog'
\fP
.fi
.RE
.LP
These extended built-in tests are still to be treated as position-sensitive
default system tests even if they are not listed in
\fB/etc/magic\fP or any other magic file.
.LP
The context-sensitive default system tests were always built into
the \fIfile\fP utility. These tests looked for language
constructs in text files trying to identify shell scripts, C, FORTRAN,
and other computer language source files, and even plain
text files. With the addition of the \fB-m\fP and \fB-M\fP options
the distinction between position-sensitive and
context-sensitive default system tests became important because the
order of testing is important. The context-sensitive system
default tests should never be applied before any position-sensitive
tests even if the \fB-d\fP option is specified before a
\fB-m\fP option or \fB-M\fP option due to the high probability that
the context-sensitive system default tests will incorrectly
identify arbitrary text files as text files before position-sensitive
tests specified by the \fB-m\fP or \fB-M\fP option would be
applied to give a more accurate identification.
.LP
Leaving the meaning of \fB-M -\fP and \fB-m -\fP unspecified allows
an existing prototype of these options to continue to work
in a backwards-compatible manner. (In that implementation, \fB-M -\fP
was roughly equivalent to \fB-d\fP in
IEEE\ Std\ 1003.1-2001.)
.LP
The historical \fB-c\fP option was omitted as not particularly useful
to users or portable shell scripts. In addition, a
reasonable implementation of the \fIfile\fP utility would report any
errors found each time the magic file is read.
.LP
The historical format of the magic file was the same as that specified
by the Rationale in the ISO\ POSIX-2:1993 standard
for the \fIoffset\fP, \fIvalue\fP, and \fImessage\fP fields; however,
it used less precise type fields than the format specified
by the current normative text. The new type field values are a superset
of the historical ones.
.LP
The following is an example magic file:
.sp
.RS
.nf
\fB0 short 070707 cpio archive
0 short 0143561 Byte-swapped cpio archive
0 string 070707 ASCII cpio archive
0 long 0177555 Very old archive
0 short 0177545 Old archive
0 short 017437 Old packed data
0 string \\037\\036 Packed data
0 string \\377\\037 Compacted data
0 string \\037\\235 Compressed data
>2 byte&0x80 >0 Block compressed
>2 byte&0x1f x %d bits
0 string \\032\\001 Compiled Terminfo Entry
0 short 0433 Curses screen image
0 short 0434 Curses screen image
0 string <ar> System V Release 1 archive
0 string !<arch>\\n__.SYMDEF Archive random library
0 string !<arch> Archive
0 string ARF_BEGARF PHIGS clear text archive
0 long 0x137A2950 Scalable OpenFont binary
0 long 0x137A2951 Encrypted scalable OpenFont binary
\fP
.fi
.RE
.LP
The use of a basic integer data type is intended to allow the implementation
to choose a word size commonly used by applications
on that architecture.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIar\fP , \fIls\fP , \fIpax\fP
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
|