Deleted Added
sdiff udiff text old ( 74784 ) new ( 80588 )
full compact
1.TH FILE __CSECTION__ "Copyright but distributable"
2.\" $Id: file.man,v 1.38 2001/03/11 20:37:08 christos Exp $
3.SH NAME
4file
5\- determine file type
6.SH SYNOPSIS
7.B file
8[
9.B \-bciknsvzL
10]
11[
12.B \-f
13namefile ]
14[
15.B \-m
16magicfiles ]
17file ...
18.br
19.B file
20.B -C
21[
22.B \-m
23magicfile ]
24.SH DESCRIPTION
25This manual page documents version __VERSION__ of the
26.B file
27command.
28.PP
29.B File
30tests each argument in an attempt to classify it.
31There are three sets of tests, performed in this order:
32filesystem tests, magic number tests, and language tests.
33The
34.I first
35test that succeeds causes the file type to be printed.
36.PP
37The type printed will usually contain one of the words
38.B text
39(the file contains only
40printing characters and a few common control
41characters and is probably safe to read on an
42.SM ASCII
43terminal),
44.B executable
45(the file contains the result of compiling a program
46in a form understandable to some \s-1UNIX\s0 kernel or another),
47or
48.B data
49meaning anything else (data is usually `binary' or non-printable).
50Exceptions are well-known file formats (core files, tar archives)
51that are known to contain binary data.
52When modifying the file
53.I __MAGIC__
54or the program itself,
55.B "preserve these keywords" .
56People depend on knowing that all the readable files in a directory
57have the word ``text'' printed.
58Don't do as Berkeley did and change ``shell commands text''
59to ``shell script''.
60Note that the file
61.I __MAGIC__
62is built mechanically from a large number of small files in
63the subdirectory
64.I Magdir
65in the source distribution of this program.
66.PP
67The filesystem tests are based on examining the return from a
68.BR stat (2)
69system call.
70The program checks to see if the file is empty,
71or if it's some sort of special file.
72Any known file types appropriate to the system you are running on
73(sockets, symbolic links, or named pipes (FIFOs) on those systems that
74implement them)
75are intuited if they are defined in
76the system header file
77.IR <sys/stat.h> .
78.PP
79The magic number tests are used to check for files with data in
80particular fixed formats.
81The canonical example of this is a binary executable (compiled program)
82.I a.out
83file, whose format is defined in
84.I a.out.h
85and possibly
86.I exec.h
87in the standard include directory.
88These files have a `magic number' stored in a particular place
89near the beginning of the file that tells the \s-1UNIX\s0 operating system
90that the file is a binary executable, and which of several types thereof.
91The concept of `magic number' has been applied by extension to data files.
92Any file with some invariant identifier at a small fixed
93offset into the file can usually be described in this way.
94The information identifying these files is read from the compiled
95magic file
96.I __MAGIC__.mgc ,
97or
98.I __MAGIC__
99if the compile file does not exist.
100.PP
101If a file does not match any of the entries in the magic file,
102it is examined to see if it seems to be a text file.
103ASCII, ISO-8859-x, non-ISO 8-bit extended-ASCII character sets
104(such as those used on Macintosh and IBM PC systems),
105UTF-8-encoded Unicode, UTF-16-encoded Unicode, and EBCDIC
106character sets can be distinguished by the different
107ranges and sequences of bytes that constitute printable text
108in each set.
109If a file passes any of these tests, its character set is reported.
110ASCII, ISO-8859-x, UTF-8, and extended-ASCII files are identified
111as ``text'' because they will be mostly readable on nearly any terminal;
112UTF-16 and EBCDIC are only ``character data'' because, while
113they contain text, it is text that will require translation
114before it can be read.
115In addition,
116.B file
117will attempt to determine other characteristics of text-type files.
118If the lines of a file are terminated by CR, CRLF, or NEL, instead
119of the Unix-standard LF, this will be reported.
120Files that contain embedded escape sequences or overstriking
121will also be identified.
122.PP
123Once
124.B file
125has determined the character set used in a text-type file,
126it will
127attempt to determine in what language the file is written.
128The language tests look for particular strings (cf
129.IR names.h )
130that can appear anywhere in the first few blocks of a file.
131For example, the keyword
132.B .br
133indicates that the file is most likely a
134.BR troff (1)
135input file, just as the keyword
136.B struct
137indicates a C program.
138These tests are less reliable than the previous
139two groups, so they are performed last.
140The language test routines also test for some miscellany
141(such as
142.BR tar (1)
143archives).
144.PP
145Any file that cannot be identified as having been written
146in any of the character sets listed above is simply said to be ``data''.
147.SH OPTIONS
148.TP 8
149.B \-b
150Do not prepend filenames to output lines (brief mode).
151.TP 8
152.B \-c
153Cause a checking printout of the parsed form of the magic file.
154This is usually used in conjunction with
155.B \-C
156Write a magic.mgc output file that contains a pre-parsed version of
157file.
158.B \-m
159to debug a new magic file before installing it.
160.TP 8
161.B \-f namefile
162Read the names of the files to be examined from
163.I namefile
164(one per line)
165before the argument list.
166Either
167.I namefile
168or at least one filename argument must be present;
169to test the standard input, use ``\-'' as a filename argument.
170.TP 8
171.B \-i
172Causes the file command to output mime type strings rather than the more
173traditional human readable ones. Thus it may say
174``text/plain; charset=us-ascii''
175rather
176than ``ASCII text''. In order for this option to work, file changes the way
177it handles files recognised by the command itself (such as many of the
178text file types, directories etc), and makes use of an alternative
179``magic'' file.
180(See ``FILES'' section, below).
181.TP 8
182.B \-k
183Don't stop at the first match, keep going.
184.TP 8
185.B \-m list
186Specify an alternate list of files containing magic numbers.
187This can be a single file, or a colon-separated list of files.
188.TP 8
189.B \-n
190Force stdout to be flushed after checking each file. This is only useful if
191checking a list of files. It is intended to be used by programs that want
192filetype output from a pipe.
193.TP 8
194.B \-v
195Print the version of the program and exit.
196.TP 8
197.B \-z
198Try to look inside compressed files.
199.TP 8
200.B \-L
201option causes symlinks to be followed, as the like-named option in
202.BR ls (1).
203(on systems that support symbolic links).
204.TP 8
205.B \-s
206Normally,
207.B file
208only attempts to read and determine the type of argument files which
209.BR stat (2)
210reports are ordinary files.
211This prevents problems, because reading special files may have peculiar
212consequences.
213Specifying the
214.BR \-s
215option causes
216.B file
217to also read argument files which are block or character special files.
218This is useful for determining the filesystem types of the data in raw
219disk partitions, which are block special files.
220This option also causes
221.B file
222to disregard the file size as reported by
223.BR stat (2)
224since on some systems it reports a zero size for raw disk partitions.
225.SH FILES
226.I __MAGIC__.mgc
227\- defaults compiled list of magic numbers
228.PP
229.I __MAGIC__
230\- default list of magic numbers
231.PP
232.I __MAGIC__.mime
233\- default list of magic numbers, used to output mime types when the -i option
234is specified.
235
236.SH ENVIRONMENT
237The environment variable
238.B MAGIC
239can be used to set the default magic number files.
240.SH SEE ALSO
241.BR magic (__FSECTION__)
242\- description of magic file format.
243.br
244.BR strings (1), " od" (1), " hexdump(1)"
245\- tools for examining non-textfiles.
246.SH STANDARDS CONFORMANCE
247This program is believed to exceed the System V Interface Definition
248of FILE(CMD), as near as one can determine from the vague language
249contained therein.
250Its behaviour is mostly compatible with the System V program of the same name.
251This version knows more magic, however, so it will produce
252different (albeit more accurate) output in many cases.
253.PP
254The one significant difference
255between this version and System V
256is that this version treats any white space
257as a delimiter, so that spaces in pattern strings must be escaped.
258For example,
259.br
260>10 string language impress\ (imPRESS data)
261.br
262in an existing magic file would have to be changed to
263.br
264>10 string language\e impress (imPRESS data)
265.br
266In addition, in this version, if a pattern string contains a backslash,
267it must be escaped. For example
268.br
2690 string \ebegindata Andrew Toolkit document
270.br
271in an existing magic file would have to be changed to
272.br
2730 string \e\ebegindata Andrew Toolkit document
274.br
275.PP
276SunOS releases 3.2 and later from Sun Microsystems include a
277.BR file (1)
278command derived from the System V one, but with some extensions.
279My version differs from Sun's only in minor ways.
280It includes the extension of the `&' operator, used as,
281for example,
282.br
283>16 long&0x7fffffff >0 not stripped
284.SH MAGIC DIRECTORY
285The magic file entries have been collected from various sources,
286mainly USENET, and contributed by various authors.
287Christos Zoulas (address below) will collect additional
288or corrected magic file entries.
289A consolidation of magic file entries
290will be distributed periodically.
291.PP
292The order of entries in the magic file is significant.
293Depending on what system you are using, the order that
294they are put together may be incorrect.
295If your old
296.B file
297command uses a magic file,
298keep the old magic file around for comparison purposes
299(rename it to
300.IR __MAGIC__.orig ).
301.SH EXAMPLES
302.nf
303$ file file.c file /dev/hda
304file.c: C program text
305file: ELF 32-bit LSB executable, Intel 80386, version 1,
306 dynamically linked, not stripped
307/dev/hda: block special
308
309$ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
310/dev/hda: x86 boot sector
311/dev/hda1: Linux/i386 ext2 filesystem
312/dev/hda2: x86 boot sector
313/dev/hda3: x86 boot sector, extended partition table
314/dev/hda4: Linux/i386 ext2 filesystem
315/dev/hda5: Linux/i386 swap file
316/dev/hda6: Linux/i386 swap file
317/dev/hda7: Linux/i386 swap file
318/dev/hda8: Linux/i386 swap file
319/dev/hda9: empty
320/dev/hda10: empty
321
322$ file -i file.c file /dev/hda
323file.c: text/x-c
324file: application/x-executable, dynamically linked (uses shared libs), not stripped
325/dev/hda: application/x-not-regular-file
326
327.fi
328.SH HISTORY
329There has been a
330.B file
331command in every \s-1UNIX\s0 since at least Research Version 6
332(man page dated January 16, 1975).
333The System V version introduced one significant major change:
334the external list of magic number types.
335This slowed the program down slightly but made it a lot more flexible.
336.PP
337This program, based on the System V version,
338was written by Ian Darwin <ian@darwinsys.com>
339without looking at anybody else's source code.
340.PP
341John Gilmore revised the code extensively, making it better than
342the first version.
343Geoff Collyer found several inadequacies
344and provided some magic file entries.
345Contributions by the `&' operator by Rob McMahon, cudcv@warwick.ac.uk, 1989.
346.PP
347Guy Harris, guy@netapp.com, made many changes from 1993 to the present.
348.PP
349Primary development and maintenance from 1990 to the present by
350Christos Zoulas (christos@astron.com).
351.PP
352Altered by Chris Lowth, chris@lowth.com, 2000:
353Handle the ``-i'' option to output mime type strings and using an alternative
354magic file and internal logic.
355.PP
356Altered by Eric Fischer (enf@pobox.com), July, 2000,
357to identify character codes and attempt to identify the languages
358of non-ASCII files.
359.PP
360The list of contributors to the "Magdir" directory (source for the
361/etc/magic
362file) is too long to include here. You know who you are; thank you.
363.SH LEGAL NOTICE
364Copyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999.
365Covered by the standard Berkeley Software Distribution copyright; see the file
366LEGAL.NOTICE in the source distribution.
367.PP
368The files
369.I tar.h
370and
371.I is_tar.c
372were written by John Gilmore from his public-domain
373.B tar
374program, and are not covered by the above license.
375.SH BUGS
376There must be a better way to automate the construction of the Magic
377file from all the glop in Magdir. What is it?
378Better yet, the magic file should be compiled into binary (say,
379.BR ndbm (3)
380or, better yet, fixed-length
381.SM ASCII
382strings for use in heterogenous network environments) for faster startup.
383Then the program would run as fast as the Version 7 program of the same name,
384with the flexibility of the System V version.
385.PP
386.B File
387uses several algorithms that favor speed over accuracy,
388thus it can be misled about the contents of
389text
390files.
391.PP
392The support for
393text
394files (primarily for programming languages)
395is simplistic, inefficient and requires recompilation to update.
396.PP
397There should be an ``else'' clause to follow a series of continuation lines.
398.PP
399The magic file and keywords should have regular expression support.
400Their use of
401.SM "ASCII TAB"
402as a field delimiter is ugly and makes
403it hard to edit the files, but is entrenched.
404.PP
405It might be advisable to allow upper-case letters in keywords
406for e.g.,
407.BR troff (1)
408commands vs man page macros.
409Regular expression support would make this easy.
410.PP
411The program doesn't grok \s-2FORTRAN\s0.
412It should be able to figure \s-2FORTRAN\s0 by seeing some keywords which
413appear indented at the start of line.
414Regular expression support would make this easy.
415.PP
416The list of keywords in
417.I ascmagic
418probably belongs in the Magic file.
419This could be done by using some keyword like `*' for the offset value.
420.PP
421Another optimisation would be to sort
422the magic file so that we can just run down all the
423tests for the first byte, first word, first long, etc, once we
424have fetched it. Complain about conflicts in the magic file entries.
425Make a rule that the magic entries sort based on file offset rather
426than position within the magic file?
427.PP
428The program should provide a way to give an estimate
429of ``how good'' a guess is.
430We end up removing guesses (e.g. ``From '' as first 5 chars of file) because
431they are not as good as other guesses (e.g. ``Newsgroups:'' versus
432``Return-Path:''). Still, if the others don't pan out, it should be
433possible to use the first guess.
434.PP
435This program is slower than some vendors' file commands.
436The new support for multiple character codes makes it even slower.
437.PP
438This manual page, and particularly this section, is too long.
439.SH AVAILABILITY
440You can obtain the original author's latest version by anonymous FTP
441on
442.B ftp.astron.com
443in the directory
444.I /pub/file/file-X.YY.tar.gz