1 | FILE(1P) POSIX Programmer's Manual FILE(1P)
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 | PROLOG
|
---|
6 | This manual page is part of the POSIX Programmer's Man-
|
---|
7 | ual. The Linux implementation of this interface may
|
---|
8 | differ (consult the corresponding Linux manual page for
|
---|
9 | details of Linux behavior), or the interface may not be
|
---|
10 | implemented on Linux.
|
---|
11 |
|
---|
12 | NAME
|
---|
13 | file - determine file type
|
---|
14 |
|
---|
15 | SYNOPSIS
|
---|
16 | file [-dh][-M file][-m file] file ...
|
---|
17 |
|
---|
18 | file -i [-h] file ...
|
---|
19 |
|
---|
20 |
|
---|
21 | DESCRIPTION
|
---|
22 | The file utility shall perform a series of tests in
|
---|
23 | sequence on each specified file in an attempt to clas-
|
---|
24 | sify it:
|
---|
25 |
|
---|
26 | 1. If file does not exist, cannot be read, or its file
|
---|
27 | status could not be determined, the output shall
|
---|
28 | indicate that the file was processed, but that its
|
---|
29 | type could not be determined.
|
---|
30 |
|
---|
31 |
|
---|
32 | 2. If the file is not a regular file, its file type
|
---|
33 | shall be identified. The file types directory,
|
---|
34 | FIFO, socket, block special, and character special
|
---|
35 | shall be identified as such. Other implementation-
|
---|
36 | defined file types may also be identified. If file
|
---|
37 | is a symbolic link, by default the link shall be
|
---|
38 | resolved and file shall test the type of file refer-
|
---|
39 | enced by the symbolic link. (See the -h and -i
|
---|
40 | options below.)
|
---|
41 |
|
---|
42 |
|
---|
43 | 3. If the length of file is zero, it shall be identi-
|
---|
44 | fied as an empty file.
|
---|
45 |
|
---|
46 |
|
---|
47 | 4. The file utility shall examine an initial segment of
|
---|
48 | file and shall make a guess at identifying its con-
|
---|
49 | tents based on position-sensitive tests. (The answer
|
---|
50 | is not guaranteed to be correct; see the -d, -M, and
|
---|
51 | -m options below.)
|
---|
52 |
|
---|
53 |
|
---|
54 | 5. The file utility shall examine file and make a guess
|
---|
55 | at identifying its contents based on context-sensi-
|
---|
56 | tive default system tests. (The answer is not guar-
|
---|
57 | anteed to be correct.)
|
---|
58 |
|
---|
59 |
|
---|
60 | 6. The file shall be identified as a data file.
|
---|
61 |
|
---|
62 |
|
---|
63 | If file does not exist, cannot be read, or its file sta-
|
---|
64 | tus could not be determined, the output shall indicate
|
---|
65 | that the file was processed, but that its type could not
|
---|
66 | be determined.
|
---|
67 |
|
---|
68 | If file is a symbolic link, by default the link shall be
|
---|
69 | resolved and file shall test the type of file referenced
|
---|
70 | by the symbolic link.
|
---|
71 |
|
---|
72 | OPTIONS
|
---|
73 | The file utility shall conform to the Base Definitions
|
---|
74 | volume of IEEE Std 1003.1-2001, Section 12.2, Utility
|
---|
75 | Syntax Guidelines, except that the order of the -m, -d,
|
---|
76 | and -M options shall be significant.
|
---|
77 |
|
---|
78 | The following options shall be supported by the imple-
|
---|
79 | mentation:
|
---|
80 |
|
---|
81 | -d Apply any position-sensitive default system tests
|
---|
82 | and context-sensitive default system tests to the
|
---|
83 | file. This is the default if no -M or -m option
|
---|
84 | is specified.
|
---|
85 |
|
---|
86 | -h When a symbolic link is encountered, identify the
|
---|
87 | file as a symbolic link. If -h is not specified
|
---|
88 | and file is a symbolic link that refers to a
|
---|
89 | nonexistent file, file shall identify the file as
|
---|
90 | a symbolic link, as if -h had been specified.
|
---|
91 |
|
---|
92 | -i If a file is a regular file, do not attempt to
|
---|
93 | classify the type of the file further, but iden-
|
---|
94 | tify the file as specified in the STDOUT section.
|
---|
95 |
|
---|
96 | -M file
|
---|
97 | Specify the name of a file containing position-
|
---|
98 | sensitive tests that shall be applied to a file
|
---|
99 | in order to classify it (see the EXTENDED
|
---|
100 | DESCRIPTION). No position-sensitive default sys-
|
---|
101 | tem tests nor context-sensitive default system
|
---|
102 | tests shall be applied unless the -d option is
|
---|
103 | also specified.
|
---|
104 |
|
---|
105 | -m file
|
---|
106 | Specify the name of a file containing position-
|
---|
107 | sensitive tests that shall be applied to a file
|
---|
108 | in order to classify it (see the EXTENDED
|
---|
109 | DESCRIPTION).
|
---|
110 |
|
---|
111 |
|
---|
112 | If the -m option is specified without specifying the -d
|
---|
113 | option or the -M option, position-sensitive default sys-
|
---|
114 | tem tests shall be applied after the position-sensitive
|
---|
115 | tests specified by the -m option. If the -M option is
|
---|
116 | specified with the -d option, the -m option, or both, or
|
---|
117 | the -m option is specified with the -d option, the con-
|
---|
118 | catenation of the position-sensitive tests specified by
|
---|
119 | these options shall be applied in the order specified by
|
---|
120 | the appearance of these options. If a -M or -m file
|
---|
121 | option-argument is -, the results are unspecified.
|
---|
122 |
|
---|
123 | OPERANDS
|
---|
124 | The following operand shall be supported:
|
---|
125 |
|
---|
126 | file A pathname of a file to be tested.
|
---|
127 |
|
---|
128 |
|
---|
129 | STDIN
|
---|
130 | Not used.
|
---|
131 |
|
---|
132 | INPUT FILES
|
---|
133 | The file can be any file type.
|
---|
134 |
|
---|
135 | ENVIRONMENT VARIABLES
|
---|
136 | The following environment variables shall affect the
|
---|
137 | execution of file:
|
---|
138 |
|
---|
139 | LANG Provide a default value for the internationaliza-
|
---|
140 | tion variables that are unset or null. (See the
|
---|
141 | Base Definitions volume of IEEE Std 1003.1-2001,
|
---|
142 | Section 8.2, Internationalization Variables for
|
---|
143 | the precedence of internationalization variables
|
---|
144 | used to determine the values of locale cate-
|
---|
145 | gories.)
|
---|
146 |
|
---|
147 | LC_ALL If set to a non-empty string value, override the
|
---|
148 | values of all the other internationalization
|
---|
149 | variables.
|
---|
150 |
|
---|
151 | LC_CTYPE
|
---|
152 | Determine the locale for the interpretation of
|
---|
153 | sequences of bytes of text data as characters
|
---|
154 | (for example, single-byte as opposed to multi-
|
---|
155 | byte characters in arguments and input files).
|
---|
156 |
|
---|
157 | LC_MESSAGES
|
---|
158 | Determine the locale that should be used to
|
---|
159 | affect the format and contents of diagnostic mes-
|
---|
160 | sages written to standard error and informative
|
---|
161 | messages written to standard output.
|
---|
162 |
|
---|
163 | NLSPATH
|
---|
164 | Determine the location of message catalogs for
|
---|
165 | the processing of LC_MESSAGES .
|
---|
166 |
|
---|
167 |
|
---|
168 | ASYNCHRONOUS EVENTS
|
---|
169 | Default.
|
---|
170 |
|
---|
171 | STDOUT
|
---|
172 | In the POSIX locale, the following format shall be used
|
---|
173 | to identify each operand, file specified:
|
---|
174 |
|
---|
175 |
|
---|
176 | "%s: %s\n", <file>, <type>
|
---|
177 |
|
---|
178 | The values for <type> are unspecified, except that in
|
---|
179 | the POSIX locale, if file is identified as one of the
|
---|
180 | types listed in the following table, <type> shall con-
|
---|
181 | tain (but is not limited to) the corresponding string,
|
---|
182 | unless the file is identified by a position-sensitive
|
---|
183 | test specified by a -M or -m option. Each space shown in
|
---|
184 | the strings shall be exactly one <space>.
|
---|
185 |
|
---|
186 | Table: File Utility Output Strings
|
---|
187 |
|
---|
188 | If file is: <type> shall contain the Notes
|
---|
189 | string:
|
---|
190 | Nonexistent cannot open
|
---|
191 | Block special block special 1
|
---|
192 | Character special character special 1
|
---|
193 | Directory directory 1
|
---|
194 | FIFO fifo 1
|
---|
195 | Socket socket 1
|
---|
196 | Symbolic link symbolic link to 1
|
---|
197 | Regular file regular file 1,2
|
---|
198 | Empty regular file empty 3
|
---|
199 | Regular file that cannot be read cannot open 3
|
---|
200 | Executable binary executable 4,6
|
---|
201 | ar archive library (see ar) archive 4,6
|
---|
202 | Extended cpio format (see pax) cpio archive 4,6
|
---|
203 | Extended tar format (see ustar in pax) tar archive 4,6
|
---|
204 | Shell script commands text 5,6
|
---|
205 | C-language source c program text 5,6
|
---|
206 | FORTRAN source fortran program text 5,6
|
---|
207 | Regular file whose type cannot be deter- data
|
---|
208 | mined
|
---|
209 |
|
---|
210 | Notes:
|
---|
211 |
|
---|
212 | 1. This is a file type test.
|
---|
213 |
|
---|
214 |
|
---|
215 | 2. This test is applied only if the -i option is
|
---|
216 | specified.
|
---|
217 |
|
---|
218 |
|
---|
219 | 3. This test is applied only if the -i option is
|
---|
220 | not specified.
|
---|
221 |
|
---|
222 |
|
---|
223 | 4. This is a position-sensitive default system
|
---|
224 | test.
|
---|
225 |
|
---|
226 |
|
---|
227 | 5. This is a context-sensitive default system
|
---|
228 | test.
|
---|
229 |
|
---|
230 |
|
---|
231 | 6. Position-sensitive default system tests and
|
---|
232 | context-sensitive default system tests are
|
---|
233 | not applied if the -M option is specified
|
---|
234 | unless the -d option is also specified.
|
---|
235 |
|
---|
236 |
|
---|
237 |
|
---|
238 | In the POSIX locale, if file is identified as a symbolic
|
---|
239 | link (see the -h option), the following alternative out-
|
---|
240 | put format shall be used:
|
---|
241 |
|
---|
242 |
|
---|
243 | "%s: %s %s\n", <file>, <type>, <contents of link>"
|
---|
244 |
|
---|
245 | If the file named by the file operand does not exist,
|
---|
246 | cannot be read, or the type of the file named by the
|
---|
247 | file operand cannot be determined, this shall not be
|
---|
248 | considered an error that affects the exit status.
|
---|
249 |
|
---|
250 | STDERR
|
---|
251 | The standard error shall be used only for diagnostic
|
---|
252 | messages.
|
---|
253 |
|
---|
254 | OUTPUT FILES
|
---|
255 | None.
|
---|
256 |
|
---|
257 | EXTENDED DESCRIPTION
|
---|
258 | A file specified as an option-argument to the -m or -M
|
---|
259 | options shall contain one position-sensitive test per
|
---|
260 | line, which shall be applied to the file. If the test
|
---|
261 | succeeds, the message field of the line shall be printed
|
---|
262 | and no further tests shall be applied, with the excep-
|
---|
263 | tion that tests on immediately following lines beginning
|
---|
264 | with a single '>' character shall be applied.
|
---|
265 |
|
---|
266 | Each line shall be composed of the following four
|
---|
267 | <blank>-separated fields:
|
---|
268 |
|
---|
269 | offset An unsigned number (optionally preceded by a sin-
|
---|
270 | gle '>' character) specifying the offset, in
|
---|
271 | bytes, of the value in the file that is to be
|
---|
272 | compared against the value field of the line. If
|
---|
273 | the file is shorter than the specified offset,
|
---|
274 | the test shall fail.
|
---|
275 |
|
---|
276 | If the offset begins with the character '>', the test
|
---|
277 | contained in the line shall not be applied to the file
|
---|
278 | unless the test on the last line for which the offset
|
---|
279 | did not begin with a '>' was successful. By default, the
|
---|
280 | offset shall be interpreted as an unsigned decimal num-
|
---|
281 | ber. With a leading 0x or 0X, the offset shall be inter-
|
---|
282 | preted as a hexadecimal number; otherwise, with a lead-
|
---|
283 | ing 0, the offset shall be interpreted as an octal num-
|
---|
284 | ber.
|
---|
285 |
|
---|
286 | type The type of the value in the file to be tested.
|
---|
287 | The type shall consist of the type specification
|
---|
288 | characters c, d, f, s, and u, specifying charac-
|
---|
289 | ter, signed decimal, floating point, string, and
|
---|
290 | unsigned decimal, respectively.
|
---|
291 |
|
---|
292 | The type string shall be interpreted as the bytes from
|
---|
293 | the file starting at the specified offset and including
|
---|
294 | the same number of bytes specified by the value field.
|
---|
295 | If insufficient bytes remain in the file past the offset
|
---|
296 | to match the value field, the test shall fail.
|
---|
297 |
|
---|
298 | The type specification characters d, f, and u can be
|
---|
299 | followed by an optional unsigned decimal integer that
|
---|
300 | specifies the number of bytes represented by the type.
|
---|
301 | The type specification character f can be followed by an
|
---|
302 | optional F, D, or L, indicating that the value is of
|
---|
303 | type float, double, or long double, respectively. The
|
---|
304 | type specification characters d and u can be followed by
|
---|
305 | an optional C, S, I, or L, indicating that the value is
|
---|
306 | of type char, short, int, or long, respectively.
|
---|
307 |
|
---|
308 | The default number of bytes represented by the type
|
---|
309 | specifiers d, f, and u shall correspond to their respec-
|
---|
310 | tive C-language types as follows. If the system claims
|
---|
311 | conformance to the C-Language Development Utilities
|
---|
312 | option, those specifiers shall correspond to the default
|
---|
313 | sizes used in the c99 utility. Otherwise, the default
|
---|
314 | sizes shall be implementation-defined.
|
---|
315 |
|
---|
316 | For the type specifier characters d and u, the default
|
---|
317 | number of bytes shall correspond to the size of a basic
|
---|
318 | integer type of the implementation. For these specifier
|
---|
319 | characters, the implementation shall support values of
|
---|
320 | the optional number of bytes to be converted correspond-
|
---|
321 | ing to the number of bytes in the C-language types char,
|
---|
322 | short, int, or long. These numbers can also be specified
|
---|
323 | by an application as the characters C, S, I, and L,
|
---|
324 | respectively. The byte order used when interpreting
|
---|
325 | numeric values is implementation-defined, but shall cor-
|
---|
326 | respond to the order in which a constant of the corre-
|
---|
327 | sponding type is stored in memory on the system.
|
---|
328 |
|
---|
329 | For the type specifier f, the default number of bytes
|
---|
330 | shall correspond to the number of bytes in the basic
|
---|
331 | double precision floating-point data type of the under-
|
---|
332 | lying implementation. The implementation shall support
|
---|
333 | values of the optional number of bytes to be converted
|
---|
334 | corresponding to the number of bytes in the C-language
|
---|
335 | types float, double, and long double. These numbers can
|
---|
336 | also be specified by an application as the characters F,
|
---|
337 | D, and L, respectively.
|
---|
338 |
|
---|
339 | All type specifiers, except for s, can be followed by a
|
---|
340 | mask specifier of the form &number. The mask value shall
|
---|
341 | be AND'ed with the value of the input file before the
|
---|
342 | comparison with the value field of the line is made. By
|
---|
343 | default, the mask shall be interpreted as an unsigned
|
---|
344 | decimal number. With a leading 0x or 0X, the mask shall
|
---|
345 | be interpreted as an unsigned hexadecimal number; other-
|
---|
346 | wise, with a leading 0, the mask shall be interpreted as
|
---|
347 | an unsigned octal number.
|
---|
348 |
|
---|
349 | The strings byte, short, long, and string shall also be
|
---|
350 | supported as type fields, being interpreted as dC, dS,
|
---|
351 | dL, and s, respectively.
|
---|
352 |
|
---|
353 | value The value to be compared with the value from the
|
---|
354 | file.
|
---|
355 |
|
---|
356 | If the specifier from the type field is s or string,
|
---|
357 | then interpret the value as a string. Otherwise, inter-
|
---|
358 | pret it as a number. If the value is a string, then the
|
---|
359 | test shall succeed only when a string value exactly
|
---|
360 | matches the bytes from the file.
|
---|
361 |
|
---|
362 | If the value is a string, it can contain the following
|
---|
363 | sequences:
|
---|
364 |
|
---|
365 | \character
|
---|
366 | The backslash-escape sequences as specified in
|
---|
367 | the Base Definitions volume of
|
---|
368 | IEEE Std 1003.1-2001, Table 5-1, Escape Sequences
|
---|
369 | and Associated Actions ( '\\', '\a', '\b', '\f',
|
---|
370 | '\n', '\r', '\t', '\v' ). The results of using
|
---|
371 | any other character, other than an octal digit,
|
---|
372 | following the backslash are unspecified.
|
---|
373 |
|
---|
374 | \octal
|
---|
375 | Octal sequences that can be used to represent
|
---|
376 | characters with specific coded values. An octal
|
---|
377 | sequence shall consist of a backslash followed by
|
---|
378 | the longest sequence of one, two, or three octal-
|
---|
379 | digit characters (01234567). If the size of a
|
---|
380 | byte on the system is greater than 9 bits, the
|
---|
381 | valid escape sequence used to represent a byte is
|
---|
382 | implementation-defined.
|
---|
383 |
|
---|
384 |
|
---|
385 | By default, any value that is not a string shall be
|
---|
386 | interpreted as a signed decimal number. Any such value,
|
---|
387 | with a leading 0x or 0X, shall be interpreted as an
|
---|
388 | unsigned hexadecimal number; otherwise, with a leading
|
---|
389 | zero, the value shall be interpreted as an unsigned
|
---|
390 | octal number.
|
---|
391 |
|
---|
392 | If the value is not a string, it can be preceded by a
|
---|
393 | character indicating the comparison to be performed.
|
---|
394 | Permissible characters and the comparisons they specify
|
---|
395 | are as follows:
|
---|
396 |
|
---|
397 | =
|
---|
398 | The test shall succeed if the value from the file
|
---|
399 | equals the value field.
|
---|
400 |
|
---|
401 | <
|
---|
402 | The test shall succeed if the value from the file
|
---|
403 | is less than the value field.
|
---|
404 |
|
---|
405 | >
|
---|
406 | The test shall succeed if the value from the file
|
---|
407 | is greater than the value field.
|
---|
408 |
|
---|
409 | &
|
---|
410 | The test shall succeed if all of the set bits in
|
---|
411 | the value field are set in the value from the
|
---|
412 | file.
|
---|
413 |
|
---|
414 | ^
|
---|
415 | The test shall succeed if at least one of the set
|
---|
416 | bits in the value field is not set in the value
|
---|
417 | from the file.
|
---|
418 |
|
---|
419 | x
|
---|
420 | The test shall succeed if the file is large
|
---|
421 | enough to contain a value of the type specified
|
---|
422 | starting at the offset specified.
|
---|
423 |
|
---|
424 |
|
---|
425 | message
|
---|
426 | The message to be printed if the test succeeds.
|
---|
427 | The message shall be interpreted using the nota-
|
---|
428 | tion for the printf formatting specification; see
|
---|
429 | printf(). If the value field was a string, then
|
---|
430 | the value from the file shall be the argument for
|
---|
431 | the printf formatting specification; otherwise,
|
---|
432 | the value from the file shall be the argument.
|
---|
433 |
|
---|
434 |
|
---|
435 | EXIT STATUS
|
---|
436 | The following exit values shall be returned:
|
---|
437 |
|
---|
438 | 0 Successful completion.
|
---|
439 |
|
---|
440 | >0 An error occurred.
|
---|
441 |
|
---|
442 |
|
---|
443 | CONSEQUENCES OF ERRORS
|
---|
444 | Default.
|
---|
445 |
|
---|
446 | The following sections are informative.
|
---|
447 |
|
---|
448 | APPLICATION USAGE
|
---|
449 | The file utility can only be required to guess at many
|
---|
450 | of the file types because only exhaustive testing can
|
---|
451 | determine some types with certainty. For example, binary
|
---|
452 | data on some implementations might match the initial
|
---|
453 | segment of an executable or a tar archive.
|
---|
454 |
|
---|
455 | Note that the table indicates that the output contains
|
---|
456 | the stated string. Systems may add text before or after
|
---|
457 | the string. For executables, as an example, the machine
|
---|
458 | architecture and various facts about how the file was
|
---|
459 | link-edited may be included. Note also that on systems
|
---|
460 | that recognize shell script files starting with "#!" as
|
---|
461 | executable files, these may be identified as executable
|
---|
462 | binary files rather than as shell scripts.
|
---|
463 |
|
---|
464 | EXAMPLES
|
---|
465 | Determine whether an argument is a binary executable
|
---|
466 | file:
|
---|
467 |
|
---|
468 |
|
---|
469 | file "$1" | grep -Fq executable &&
|
---|
470 | printf "%s is executable.\n" "$1"
|
---|
471 |
|
---|
472 | RATIONALE
|
---|
473 | The -f option was omitted because the same effect can
|
---|
474 | (and should) be obtained using the xargs utility.
|
---|
475 |
|
---|
476 | Historical versions of the file utility attempt to iden-
|
---|
477 | tify the following types of files: symbolic link, direc-
|
---|
478 | tory, character special, block special, socket, tar ar-
|
---|
479 | chive, cpio archive, SCCS archive, archive library,
|
---|
480 | empty, compress output, pack output, binary data, C
|
---|
481 | source, FORTRAN source, assembler source, nroff/ troff/
|
---|
482 | eqn/ tbl source troff output, shell script, C shell
|
---|
483 | script, English text, ASCII text, various executables,
|
---|
484 | APL workspace, compiled terminfo entries, and CURSES
|
---|
485 | screen images. Only those types that are reasonably well
|
---|
486 | specified in POSIX or are directly related to POSIX
|
---|
487 | utilities are listed in the table.
|
---|
488 |
|
---|
489 | Historical systems have used a "magic file" named
|
---|
490 | /etc/magic to help identify file types. Because it is
|
---|
491 | generally useful for users and scripts to be able to
|
---|
492 | identify special file types, the -m flag and a portable
|
---|
493 | format for user-created magic files has been specified.
|
---|
494 | No requirement is made that an implementation of file
|
---|
495 | use this method of identifying files, only that users be
|
---|
496 | permitted to add their own classifying tests.
|
---|
497 |
|
---|
498 | In addition, three options have been added to historical
|
---|
499 | practice. The -d flag has been added to permit users to
|
---|
500 | cause their tests to follow any default system tests.
|
---|
501 | The -i flag has been added to permit users to test
|
---|
502 | portably for regular files in shell scripts. The -M flag
|
---|
503 | has been added to permit users to ignore any default
|
---|
504 | system tests.
|
---|
505 |
|
---|
506 | The IEEE Std 1003.1-2001 description of default system
|
---|
507 | tests and the interaction between the -d, -M, and -m
|
---|
508 | options did not clearly indicate that there were two
|
---|
509 | types of "default system tests". The "position-sensitive
|
---|
510 | tests'' determine file types by looking for certain
|
---|
511 | string or binary values at specific offsets in the file
|
---|
512 | being examined. These position-sensitive tests were
|
---|
513 | implemented in historical systems using the magic file
|
---|
514 | described above. Some of these tests are now built into
|
---|
515 | the file utility itself on some implementations so the
|
---|
516 | output can provide more detail than can be provided by
|
---|
517 | magic files. For example, a magic file can easily iden-
|
---|
518 | tify a core file on most implementations, but cannot
|
---|
519 | name the program file that dropped the core. A magic
|
---|
520 | file could produce output such as:
|
---|
521 |
|
---|
522 |
|
---|
523 | /home/dwc/core: ELF 32-bit MSB core file SPARC Version 1
|
---|
524 |
|
---|
525 | but by building the test into the file utility, you
|
---|
526 | could get output such as:
|
---|
527 |
|
---|
528 |
|
---|
529 | /home/dwc/core: ELF 32-bit MSB core file SPARC Version 1, from 'testprog'
|
---|
530 |
|
---|
531 | These extended built-in tests are still to be treated as
|
---|
532 | position-sensitive default system tests even if they are
|
---|
533 | not listed in /etc/magic or any other magic file.
|
---|
534 |
|
---|
535 | The context-sensitive default system tests were always
|
---|
536 | built into the file utility. These tests looked for lan-
|
---|
537 | guage constructs in text files trying to identify shell
|
---|
538 | scripts, C, FORTRAN, and other computer language source
|
---|
539 | files, and even plain text files. With the addition of
|
---|
540 | the -m and -M options the distinction between position-
|
---|
541 | sensitive and context-sensitive default system tests
|
---|
542 | became important because the order of testing is impor-
|
---|
543 | tant. The context-sensitive system default tests should
|
---|
544 | never be applied before any position-sensitive tests
|
---|
545 | even if the -d option is specified before a -m option or
|
---|
546 | -M option due to the high probability that the context-
|
---|
547 | sensitive system default tests will incorrectly identify
|
---|
548 | arbitrary text files as text files before position-sen-
|
---|
549 | sitive tests specified by the -m or -M option would be
|
---|
550 | applied to give a more accurate identification.
|
---|
551 |
|
---|
552 | Leaving the meaning of -M - and -m - unspecified allows
|
---|
553 | an existing prototype of these options to continue to
|
---|
554 | work in a backwards-compatible manner. (In that imple-
|
---|
555 | mentation, -M - was roughly equivalent to -d in
|
---|
556 | IEEE Std 1003.1-2001.)
|
---|
557 |
|
---|
558 | The historical -c option was omitted as not particularly
|
---|
559 | useful to users or portable shell scripts. In addition,
|
---|
560 | a reasonable implementation of the file utility would
|
---|
561 | report any errors found each time the magic file is
|
---|
562 | read.
|
---|
563 |
|
---|
564 | The historical format of the magic file was the same as
|
---|
565 | that specified by the Rationale in the ISO POSIX-2:1993
|
---|
566 | standard for the offset, value, and message fields; how-
|
---|
567 | ever, it used less precise type fields than the format
|
---|
568 | specified by the current normative text. The new type
|
---|
569 | field values are a superset of the historical ones.
|
---|
570 |
|
---|
571 | The following is an example magic file:
|
---|
572 |
|
---|
573 |
|
---|
574 | 0 short 070707 cpio archive
|
---|
575 | 0 short 0143561 Byte-swapped cpio archive
|
---|
576 | 0 string 070707 ASCII cpio archive
|
---|
577 | 0 long 0177555 Very old archive
|
---|
578 | 0 short 0177545 Old archive
|
---|
579 | 0 short 017437 Old packed data
|
---|
580 | 0 string \037\036 Packed data
|
---|
581 | 0 string \377\037 Compacted data
|
---|
582 | 0 string \037\235 Compressed data
|
---|
583 | >2 byte&0x80 >0 Block compressed
|
---|
584 | >2 byte&0x1f x %d bits
|
---|
585 | 0 string \032\001 Compiled Terminfo Entry
|
---|
586 | 0 short 0433 Curses screen image
|
---|
587 | 0 short 0434 Curses screen image
|
---|
588 | 0 string <ar> System V Release 1 archive
|
---|
589 | 0 string !<arch>\n__.SYMDEF Archive random library
|
---|
590 | 0 string !<arch> Archive
|
---|
591 | 0 string ARF_BEGARF PHIGS clear text archive
|
---|
592 | 0 long 0x137A2950 Scalable OpenFont binary
|
---|
593 | 0 long 0x137A2951 Encrypted scalable OpenFont binary
|
---|
594 |
|
---|
595 | The use of a basic integer data type is intended to
|
---|
596 | allow the implementation to choose a word size commonly
|
---|
597 | used by applications on that architecture.
|
---|
598 |
|
---|
599 | FUTURE DIRECTIONS
|
---|
600 | None.
|
---|
601 |
|
---|
602 | SEE ALSO
|
---|
603 | ar, ls, pax
|
---|
604 |
|
---|
605 | COPYRIGHT
|
---|
606 | Portions of this text are reprinted and reproduced in
|
---|
607 | electronic form from IEEE Std 1003.1, 2003 Edition,
|
---|
608 | Standard for Information Technology -- Portable Operat-
|
---|
609 | ing System Interface (POSIX), The Open Group Base Speci-
|
---|
610 | fications Issue 6, Copyright (C) 2001-2003 by the Insti-
|
---|
611 | tute of Electrical and Electronics Engineers, Inc and
|
---|
612 | The Open Group. In the event of any discrepancy between
|
---|
613 | this version and the original IEEE and The Open Group
|
---|
614 | Standard, the original IEEE and The Open Group Standard
|
---|
615 | is the referee document. The original Standard can be
|
---|
616 | obtained online at http://www.open-
|
---|
617 | group.org/unix/online.html .
|
---|
618 |
|
---|
619 |
|
---|
620 |
|
---|
621 | IEEE/The Open Group 2003 FILE(1P)
|
---|