1 .TH FILE 1 "Copyright but distributable"
31 This manual page documents version 4.02 of the
36 tests each argument in an attempt to classify it.
37 There are three sets of tests, performed in this order:
38 filesystem tests, magic number tests, and language tests.
41 test that succeeds causes the file type to be printed.
43 The type printed will usually contain one of the words
45 (the file contains only
46 printing characters and a few common control
47 characters and is probably safe to read on an
51 (the file contains the result of compiling a program
52 in a form understandable to some \s-1UNIX\s0 kernel or another),
55 meaning anything else (data is usually `binary' or non-printable).
56 Exceptions are well-known file formats (core files, tar archives)
57 that are known to contain binary data.
58 When modifying the file
59 .I /usr/share/file/magic
60 or the program itself,
61 .B "preserve these keywords" .
62 People depend on knowing that all the readable files in a directory
63 have the word ``text'' printed.
64 Don't do as Berkeley did and change ``shell commands text''
67 .I /usr/share/file/magic
68 is built mechanically from a large number of small files in
71 in the source distribution of this program.
73 The filesystem tests are based on examining the return from a
76 The program checks to see if the file is empty,
77 or if it's some sort of special file.
78 Any known file types appropriate to the system you are running on
79 (sockets, symbolic links, or named pipes (FIFOs) on those systems that
81 are intuited if they are defined in
82 the system header file
85 The magic number tests are used to check for files with data in
86 particular fixed formats.
87 The canonical example of this is a binary executable (compiled program)
89 file, whose format is defined in
93 in the standard include directory.
94 These files have a `magic number' stored in a particular place
95 near the beginning of the file that tells the \s-1UNIX\s0 operating system
96 that the file is a binary executable, and which of several types thereof.
97 The concept of `magic number' has been applied by extension to data files.
98 Any file with some invariant identifier at a small fixed
99 offset into the file can usually be described in this way.
100 The information identifying these files is read from the compiled
102 .I /usr/share/file/magic.mgc ,
104 .I /usr/share/file/magic
105 if the compile file does not exist.
107 If a file does not match any of the entries in the magic file,
108 it is examined to see if it seems to be a text file.
109 ASCII, ISO-8859-x, non-ISO 8-bit extended-ASCII character sets
110 (such as those used on Macintosh and IBM PC systems),
111 UTF-8-encoded Unicode, UTF-16-encoded Unicode, and EBCDIC
112 character sets can be distinguished by the different
113 ranges and sequences of bytes that constitute printable text
115 If a file passes any of these tests, its character set is reported.
116 ASCII, ISO-8859-x, UTF-8, and extended-ASCII files are identified
117 as ``text'' because they will be mostly readable on nearly any terminal;
118 UTF-16 and EBCDIC are only ``character data'' because, while
119 they contain text, it is text that will require translation
120 before it can be read.
123 will attempt to determine other characteristics of text-type files.
124 If the lines of a file are terminated by CR, CRLF, or NEL, instead
125 of the Unix-standard LF, this will be reported.
126 Files that contain embedded escape sequences or overstriking
127 will also be identified.
131 has determined the character set used in a text-type file,
133 attempt to determine in what language the file is written.
134 The language tests look for particular strings (cf
136 that can appear anywhere in the first few blocks of a file.
137 For example, the keyword
139 indicates that the file is most likely a
141 input file, just as the keyword
143 indicates a C program.
144 These tests are less reliable than the previous
145 two groups, so they are performed last.
146 The language test routines also test for some miscellany
151 Any file that cannot be identified as having been written
152 in any of the character sets listed above is simply said to be ``data''.
156 Do not prepend filenames to output lines (brief mode).
159 Cause a checking printout of the parsed form of the magic file.
160 This is usually used in conjunction with
162 to debug a new magic file before installing it.
165 Write a magic.mgc output file that contains a pre-parsed version of
169 Read the names of the files to be examined from
172 before the argument list.
175 or at least one filename argument must be present;
176 to test the standard input, use ``\-'' as a filename argument.
179 Use the specified string as the separator between the filename and the
180 file result returned. Defaults to ``:''.
183 Causes the file command to output mime type strings rather than the more
184 traditional human readable ones. Thus it may say
185 ``text/plain; charset=us-ascii''
188 In order for this option to work, file changes the way
189 it handles files recognised by the command itself (such as many of the
190 text file types, directories etc), and makes use of an alternative
192 (See ``FILES'' section, below).
195 Don't stop at the first match, keep going.
198 option causes symlinks to be followed, as the like-named option in
200 (on systems that support symbolic links).
203 Specify an alternate list of files containing magic numbers.
204 This can be a single file, or a colon-separated list of files.
207 Force stdout to be flushed after checking each file.
208 This is only useful if checking a list of files.
209 It is intended to be used by programs that want filetype output from a pipe.
212 Don't pad filenames so that they align in the output.
217 only attempts to read and determine the type of argument files which
219 reports are ordinary files.
220 This prevents problems, because reading special files may have peculiar
226 to also read argument files which are block or character special files.
227 This is useful for determining the filesystem types of the data in raw
228 disk partitions, which are block special files.
229 This option also causes
231 to disregard the file size as reported by
233 since on some systems it reports a zero size for raw disk partitions.
236 Print the version of the program and exit.
239 Try to look inside compressed files.
241 .I /usr/share/file/magic.mgc
242 \- default compiled list of magic numbers
244 .I /usr/share/file/magic
245 \- default list of magic numbers
247 .I /usr/share/file/magic.mime.mgc
248 \- default compiled list of magic numbers, used to output mime types when
249 the -i option is specified.
251 .I /usr/share/file/magic.mime
252 \- default list of magic numbers, used to output mime types when the -i option
256 The environment variable
258 can be used to set the default magic number files.
261 \- description of magic file format.
263 .BR strings (1), " od" (1), " hexdump(1)"
264 \- tools for examining non-textfiles.
265 .SH STANDARDS CONFORMANCE
266 This program is believed to exceed the System V Interface Definition
267 of FILE(CMD), as near as one can determine from the vague language
269 Its behaviour is mostly compatible with the System V program of the same name.
270 This version knows more magic, however, so it will produce
271 different (albeit more accurate) output in many cases.
273 The one significant difference
274 between this version and System V
275 is that this version treats any white space
276 as a delimiter, so that spaces in pattern strings must be escaped.
279 >10 string language impress\ (imPRESS data)
281 in an existing magic file would have to be changed to
283 >10 string language\e impress (imPRESS data)
285 In addition, in this version, if a pattern string contains a backslash,
289 0 string \ebegindata Andrew Toolkit document
291 in an existing magic file would have to be changed to
293 0 string \e\ebegindata Andrew Toolkit document
296 SunOS releases 3.2 and later from Sun Microsystems include a
298 command derived from the System V one, but with some extensions.
299 My version differs from Sun's only in minor ways.
300 It includes the extension of the `&' operator, used as,
303 >16 long&0x7fffffff >0 not stripped
305 The magic file entries have been collected from various sources,
306 mainly USENET, and contributed by various authors.
307 Christos Zoulas (address below) will collect additional
308 or corrected magic file entries.
309 A consolidation of magic file entries
310 will be distributed periodically.
312 The order of entries in the magic file is significant.
313 Depending on what system you are using, the order that
314 they are put together may be incorrect.
317 command uses a magic file,
318 keep the old magic file around for comparison purposes
320 .IR /usr/share/file/magic.orig ).
323 $ file file.c file /dev/{wd0a,hda}
324 file.c: C program text
325 file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
326 dynamically linked (uses shared libs), stripped
327 /dev/wd0a: block special (0/0)
328 /dev/hda: block special (3/0)
329 $ file -s /dev/wd0{b,d}
331 /dev/wd0d: x86 boot sector
332 $ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
333 /dev/hda: x86 boot sector
334 /dev/hda1: Linux/i386 ext2 filesystem
335 /dev/hda2: x86 boot sector
336 /dev/hda3: x86 boot sector, extended partition table
337 /dev/hda4: Linux/i386 ext2 filesystem
338 /dev/hda5: Linux/i386 swap file
339 /dev/hda6: Linux/i386 swap file
340 /dev/hda7: Linux/i386 swap file
341 /dev/hda8: Linux/i386 swap file
345 $ file -i file.c file /dev/{wd0a,hda}
347 file: application/x-executable, dynamically linked (uses shared libs),
349 /dev/hda: application/x-not-regular-file
350 /dev/wd0a: application/x-not-regular-file
356 command in every \s-1UNIX\s0 since at least Research Version 4
357 (man page dated November, 1973).
358 The System V version introduced one significant major change:
359 the external list of magic number types.
360 This slowed the program down slightly but made it a lot more flexible.
362 This program, based on the System V version,
363 was written by Ian Darwin <ian@darwinsys.com>
364 without looking at anybody else's source code.
366 John Gilmore revised the code extensively, making it better than
368 Geoff Collyer found several inadequacies
369 and provided some magic file entries.
370 Contributions by the `&' operator by Rob McMahon, cudcv@warwick.ac.uk, 1989.
372 Guy Harris, guy@netapp.com, made many changes from 1993 to the present.
374 Primary development and maintenance from 1990 to the present by
375 Christos Zoulas (christos@astron.com).
377 Altered by Chris Lowth, chris@lowth.com, 2000:
378 Handle the ``-i'' option to output mime type strings and using an alternative
379 magic file and internal logic.
381 Altered by Eric Fischer (enf@pobox.com), July, 2000,
382 to identify character codes and attempt to identify the languages
385 The list of contributors to the "Magdir" directory (source for the
387 file) is too long to include here.
388 You know who you are; thank you.
390 Copyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999.
391 Covered by the standard Berkeley Software Distribution copyright; see the file
392 LEGAL.NOTICE in the source distribution.
398 were written by John Gilmore from his public-domain
400 program, and are not covered by the above license.
402 There must be a better way to automate the construction of the Magic
403 file from all the glop in magdir.
405 Better yet, the magic file should be compiled into binary (say,
407 or, better yet, fixed-length
409 strings for use in heterogenous network environments) for faster startup.
410 Then the program would run as fast as the Version 7 program of the same name,
411 with the flexibility of the System V version.
414 uses several algorithms that favor speed over accuracy,
415 thus it can be misled about the contents of
421 files (primarily for programming languages)
422 is simplistic, inefficient and requires recompilation to update.
424 There should be an ``else'' clause to follow a series of continuation lines.
426 The magic file and keywords should have regular expression support.
429 as a field delimiter is ugly and makes
430 it hard to edit the files, but is entrenched.
432 It might be advisable to allow upper-case letters in keywords
435 commands vs man page macros.
436 Regular expression support would make this easy.
438 The program doesn't grok \s-2FORTRAN\s0.
439 It should be able to figure \s-2FORTRAN\s0 by seeing some keywords which
440 appear indented at the start of line.
441 Regular expression support would make this easy.
443 The list of keywords in
445 probably belongs in the Magic file.
446 This could be done by using some keyword like `*' for the offset value.
448 Another optimisation would be to sort
449 the magic file so that we can just run down all the
450 tests for the first byte, first word, first long, etc, once we
452 Complain about conflicts in the magic file entries.
453 Make a rule that the magic entries sort based on file offset rather
454 than position within the magic file?
456 The program should provide a way to give an estimate
457 of ``how good'' a guess is.
458 We end up removing guesses (e.g. ``From '' as first 5 chars of file) because
459 they are not as good as other guesses (e.g. ``Newsgroups:'' versus
461 Still, if the others don't pan out, it should be possible to use the
464 This program is slower than some vendors' file commands.
465 The new support for multiple character codes makes it even slower.
467 This manual page, and particularly this section, is too long.
469 You can obtain the original author's latest version by anonymous FTP
473 .I /pub/file/file-X.YZ.tar.gz