1 .TH FILE __CSECTION__ "Copyright but distributable"
2 .\" $Id: file.man,v 1.59 2006/11/17 16:11:10 christos Exp $
32 This manual page documents version __VERSION__ of the
37 tests each argument in an attempt to classify it.
38 There are three sets of tests, performed in this order:
39 filesystem tests, magic number tests, and language tests.
42 test that succeeds causes the file type to be printed.
44 The type printed will usually contain one of the words
46 (the file contains only
47 printing characters and a few common control
48 characters and is probably safe to read on an
52 (the file contains the result of compiling a program
53 in a form understandable to some \s-1UNIX\s0 kernel or another),
56 meaning anything else (data is usually `binary' or non-printable).
57 Exceptions are well-known file formats (core files, tar archives)
58 that are known to contain binary data.
59 When modifying the file
61 or the program itself,
62 .B "preserve these keywords" .
63 People depend on knowing that all the readable files in a directory
64 have the word ``text'' printed.
65 Don't do as Berkeley did and change ``shell commands text''
69 is built mechanically from a large number of small files in
72 in the source distribution of this program.
74 The filesystem tests are based on examining the return from a
77 The program checks to see if the file is empty,
78 or if it's some sort of special file.
79 Any known file types appropriate to the system you are running on
80 (sockets, symbolic links, or named pipes (FIFOs) on those systems that
82 are intuited if they are defined in
83 the system header file
86 The magic number tests are used to check for files with data in
87 particular fixed formats.
88 The canonical example of this is a binary executable (compiled program)
90 file, whose format is defined in
94 in the standard include directory.
95 These files have a `magic number' stored in a particular place
96 near the beginning of the file that tells the \s-1UNIX\s0 operating system
97 that the file is a binary executable, and which of several types thereof.
98 The concept of `magic number' has been applied by extension to data files.
99 Any file with some invariant identifier at a small fixed
100 offset into the file can usually be described in this way.
101 The information identifying these files is read from the compiled
106 if the compile file does not exist. In addition
109 .I $HOME/.magic.mgc ,
114 If a file does not match any of the entries in the magic file,
115 it is examined to see if it seems to be a text file.
116 ASCII, ISO-8859-x, non-ISO 8-bit extended-ASCII character sets
117 (such as those used on Macintosh and IBM PC systems),
118 UTF-8-encoded Unicode, UTF-16-encoded Unicode, and EBCDIC
119 character sets can be distinguished by the different
120 ranges and sequences of bytes that constitute printable text
122 If a file passes any of these tests, its character set is reported.
123 ASCII, ISO-8859-x, UTF-8, and extended-ASCII files are identified
124 as ``text'' because they will be mostly readable on nearly any terminal;
125 UTF-16 and EBCDIC are only ``character data'' because, while
126 they contain text, it is text that will require translation
127 before it can be read.
130 will attempt to determine other characteristics of text-type files.
131 If the lines of a file are terminated by CR, CRLF, or NEL, instead
132 of the Unix-standard LF, this will be reported.
133 Files that contain embedded escape sequences or overstriking
134 will also be identified.
138 has determined the character set used in a text-type file,
140 attempt to determine in what language the file is written.
141 The language tests look for particular strings (cf
143 that can appear anywhere in the first few blocks of a file.
144 For example, the keyword
146 indicates that the file is most likely a
148 input file, just as the keyword
150 indicates a C program.
151 These tests are less reliable than the previous
152 two groups, so they are performed last.
153 The language test routines also test for some miscellany
158 Any file that cannot be identified as having been written
159 in any of the character sets listed above is simply said to be ``data''.
163 Do not prepend filenames to output lines (brief mode).
165 .B "\-c, \-\-checking\-printout"
166 Cause a checking printout of the parsed form of the magic file.
167 This is usually used in conjunction with
169 to debug a new magic file before installing it.
171 .B "\-C, \-\-compile"
172 Write a magic.mgc output file that contains a pre-parsed version of
175 .BI "\-f, \-\-files\-from" " namefile"
176 Read the names of the files to be examined from
179 before the argument list.
182 or at least one filename argument must be present;
183 to test the standard input, use ``\-'' as a filename argument.
185 .BI "\-F, \-\-separator" " separator"
186 Use the specified string as the separator between the filename and the
187 file result returned. Defaults to ``:''.
189 .B "\-h, \-\-no-dereference"
190 option causes symlinks not to be followed
191 (on systems that support symbolic links). This is the default if the
197 Causes the file command to output mime type strings rather than the more
198 traditional human readable ones. Thus it may say
199 ``text/plain; charset=us-ascii''
202 In order for this option to work, file changes the way
203 it handles files recognized by the command itself (such as many of the
204 text file types, directories etc), and makes use of an alternative
206 (See ``FILES'' section, below).
208 .B "\-k, \-\-keep\-going"
209 Don't stop at the first match, keep going.
211 .B "\-L, \-\-dereference"
212 option causes symlinks to be followed, as the like-named option in
214 (on systems that support symbolic links).
215 This is the default if the environment variable
219 .BI "\-m, \-\-magic\-file" " list"
220 Specify an alternate list of files containing magic numbers.
221 This can be a single file, or a colon-separated list of files.
222 If a compiled magic file is found alongside, it will be used instead.
223 With the \-i or \-\-mime option, the program adds ".mime" to each file name.
225 .B "\-n, \-\-no\-buffer"
226 Force stdout to be flushed after checking each file.
227 This is only useful if checking a list of files.
228 It is intended to be used by programs that want filetype output from a pipe.
230 .B "\-N, \-\-no\-pad"
231 Don't pad filenames so that they align in the output.
233 .B "\-p, \-\-preserve\-date"
234 On systems that support
238 attempt to preserve the access time of files analyzed, to pretend that
243 Don't translate unprintable characters to \eooo.
246 translates unprintable characters to their octal representation.
248 .B "\-s, \-\-special\-files"
251 only attempts to read and determine the type of argument files which
253 reports are ordinary files.
254 This prevents problems, because reading special files may have peculiar
260 to also read argument files which are block or character special files.
261 This is useful for determining the filesystem types of the data in raw
262 disk partitions, which are block special files.
263 This option also causes
265 to disregard the file size as reported by
267 since on some systems it reports a zero size for raw disk partitions.
269 .B "\-v, \-\-version"
270 Print the version of the program and exit.
272 .B "\-z, \-\-uncompress"
273 Try to look inside compressed files.
275 Output a null character ('\0') after the end of the filename. Nice to
277 the output. This does not affect the separator which is still printed.
280 Print a help message and exit.
284 Default compiled list of magic numbers
287 Default list of magic numbers
289 .I __MAGIC__.mime.mgc
290 Default compiled list of magic numbers, used to output mime types when
291 the -i option is specified.
294 Default list of magic numbers, used to output mime types when the -i option
298 The environment variable
300 can be used to set the default magic number file name.
301 If that variable is set, then
303 will not attempt to open
306 adds ".mime" and/or ".mgc" to the value of this variable as appropriate.
307 The environment variable
309 controls (on systems that support symbolic links), if
311 will attempt to follow symlinks or not. If set, then
313 follows symlink, otherwise it does not. This is also controlled
320 .BR magic (__FSECTION__)
321 \- description of magic file format.
323 .BR strings (1), " od" (1), " hexdump(1)"
324 \- tools for examining non-textfiles.
325 .SH STANDARDS CONFORMANCE
326 This program is believed to exceed the System V Interface Definition
327 of FILE(CMD), as near as one can determine from the vague language
329 Its behavior is mostly compatible with the System V program of the same name.
330 This version knows more magic, however, so it will produce
331 different (albeit more accurate) output in many cases.
332 .\" URL: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html
334 The one significant difference
335 between this version and System V
336 is that this version treats any white space
337 as a delimiter, so that spaces in pattern strings must be escaped.
340 >10 string language impress\ (imPRESS data)
342 in an existing magic file would have to be changed to
344 >10 string language\e impress (imPRESS data)
346 In addition, in this version, if a pattern string contains a backslash,
350 0 string \ebegindata Andrew Toolkit document
352 in an existing magic file would have to be changed to
354 0 string \e\ebegindata Andrew Toolkit document
357 SunOS releases 3.2 and later from Sun Microsystems include a
359 command derived from the System V one, but with some extensions.
360 My version differs from Sun's only in minor ways.
361 It includes the extension of the `&' operator, used as,
364 >16 long&0x7fffffff >0 not stripped
366 The magic file entries have been collected from various sources,
367 mainly USENET, and contributed by various authors.
368 Christos Zoulas (address below) will collect additional
369 or corrected magic file entries.
370 A consolidation of magic file entries
371 will be distributed periodically.
373 The order of entries in the magic file is significant.
374 Depending on what system you are using, the order that
375 they are put together may be incorrect.
378 command uses a magic file,
379 keep the old magic file around for comparison purposes
381 .IR __MAGIC__.orig ).
384 $ file file.c file /dev/{wd0a,hda}
385 file.c: C program text
386 file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
387 dynamically linked (uses shared libs), stripped
388 /dev/wd0a: block special (0/0)
389 /dev/hda: block special (3/0)
390 $ file -s /dev/wd0{b,d}
392 /dev/wd0d: x86 boot sector
393 $ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
394 /dev/hda: x86 boot sector
395 /dev/hda1: Linux/i386 ext2 filesystem
396 /dev/hda2: x86 boot sector
397 /dev/hda3: x86 boot sector, extended partition table
398 /dev/hda4: Linux/i386 ext2 filesystem
399 /dev/hda5: Linux/i386 swap file
400 /dev/hda6: Linux/i386 swap file
401 /dev/hda7: Linux/i386 swap file
402 /dev/hda8: Linux/i386 swap file
406 $ file -i file.c file /dev/{wd0a,hda}
408 file: application/x-executable, dynamically linked (uses shared libs),
410 /dev/hda: application/x-not-regular-file
411 /dev/wd0a: application/x-not-regular-file
417 command in every \s-1UNIX\s0 since at least Research Version 4
418 (man page dated November, 1973).
419 The System V version introduced one significant major change:
420 the external list of magic number types.
421 This slowed the program down slightly but made it a lot more flexible.
423 This program, based on the System V version,
424 was written by Ian Darwin <ian@darwinsys.com>
425 without looking at anybody else's source code.
427 John Gilmore revised the code extensively, making it better than
429 Geoff Collyer found several inadequacies
430 and provided some magic file entries.
431 Contributions by the `&' operator by Rob McMahon, cudcv@warwick.ac.uk, 1989.
433 Guy Harris, guy@netapp.com, made many changes from 1993 to the present.
435 Primary development and maintenance from 1990 to the present by
436 Christos Zoulas (christos@astron.com).
438 Altered by Chris Lowth, chris@lowth.com, 2000:
439 Handle the ``-i'' option to output mime type strings and using an alternative
440 magic file and internal logic.
442 Altered by Eric Fischer (enf@pobox.com), July, 2000,
443 to identify character codes and attempt to identify the languages
446 The list of contributors to the "Magdir" directory (source for the
448 file) is too long to include here.
449 You know who you are; thank you.
451 Copyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999.
452 Covered by the standard Berkeley Software Distribution copyright; see the file
453 LEGAL.NOTICE in the source distribution.
459 were written by John Gilmore from his public-domain
461 program, and are not covered by the above license.
463 There must be a better way to automate the construction of the Magic
464 file from all the glop in Magdir.
466 Better yet, the magic file should be compiled into binary (say,
468 or, better yet, fixed-length
470 strings for use in heterogenous network environments) for faster startup.
471 Then the program would run as fast as the Version 7 program of the same name,
472 with the flexibility of the System V version.
475 uses several algorithms that favor speed over accuracy,
476 thus it can be misled about the contents of
482 files (primarily for programming languages)
483 is simplistic, inefficient and requires recompilation to update.
485 There should be an ``else'' clause to follow a series of continuation lines.
487 The magic file and keywords should have regular expression support.
490 as a field delimiter is ugly and makes
491 it hard to edit the files, but is entrenched.
493 It might be advisable to allow upper-case letters in keywords
496 commands vs man page macros.
497 Regular expression support would make this easy.
499 The program doesn't grok \s-2FORTRAN\s0.
500 It should be able to figure \s-2FORTRAN\s0 by seeing some keywords which
501 appear indented at the start of line.
502 Regular expression support would make this easy.
504 The list of keywords in
506 probably belongs in the Magic file.
507 This could be done by using some keyword like `*' for the offset value.
509 Another optimization would be to sort
510 the magic file so that we can just run down all the
511 tests for the first byte, first word, first long, etc, once we
513 Complain about conflicts in the magic file entries.
514 Make a rule that the magic entries sort based on file offset rather
515 than position within the magic file?
517 The program should provide a way to give an estimate
518 of ``how good'' a guess is.
519 We end up removing guesses (e.g. ``From '' as first 5 chars of file) because
520 they are not as good as other guesses (e.g. ``Newsgroups:'' versus
522 Still, if the others don't pan out, it should be possible to use the
525 This program is slower than some vendors' file commands.
526 The new support for multiple character codes makes it even slower.
528 This manual page, and particularly this section, is too long.
530 You can obtain the original author's latest version by anonymous FTP
534 .I /pub/file/file-X.YZ.tar.gz