xref: /dflybsd-src/contrib/file/doc/file.man (revision 884044a574904c56cc0441938f957625f5153d6c)
1*884044a5SPeter Avalos.\" $File: file.man,v 1.94 2011/04/20 19:08:44 christos Exp $
2*884044a5SPeter Avalos.Dd April 20, 2011
3327e51cbSPeter Avalos.Dt FILE __CSECTION__
4327e51cbSPeter Avalos.Os
5327e51cbSPeter Avalos.Sh NAME
6327e51cbSPeter Avalos.Nm file
7327e51cbSPeter Avalos.Nd determine file type
8327e51cbSPeter Avalos.Sh SYNOPSIS
9327e51cbSPeter Avalos.Nm
10f72f8299SJan Lentfer.Bk -words
11e4d4ce0cSPeter Avalos.Op Fl bchiklLNnprsvz0
12f72f8299SJan Lentfer.Op Fl -apple
1379343712SPeter Avalos.Op Fl -mime-encoding
14f72f8299SJan Lentfer.Op Fl -mime-type
15f72f8299SJan Lentfer.Op Fl e Ar testname
16327e51cbSPeter Avalos.Op Fl F Ar separator
17f72f8299SJan Lentfer.Op Fl f Ar namefile
18327e51cbSPeter Avalos.Op Fl m Ar magicfiles
19f72f8299SJan Lentfer.Ar
20f72f8299SJan Lentfer.Ek -words
21327e51cbSPeter Avalos.Nm
22327e51cbSPeter Avalos.Fl C
23f72f8299SJan Lentfer.Op Fl m Ar magicfiles
2479343712SPeter Avalos.Nm
2579343712SPeter Avalos.Op Fl -help
26327e51cbSPeter Avalos.Sh DESCRIPTION
27327e51cbSPeter AvalosThis manual page documents version __VERSION__ of the
28327e51cbSPeter Avalos.Nm
29327e51cbSPeter Avaloscommand.
30327e51cbSPeter Avalos.Pp
31327e51cbSPeter Avalos.Nm
32327e51cbSPeter Avalostests each argument in an attempt to classify it.
33327e51cbSPeter AvalosThere are three sets of tests, performed in this order:
3479343712SPeter Avalosfilesystem tests, magic tests, and language tests.
35327e51cbSPeter AvalosThe
36327e51cbSPeter Avalos.Em first
37327e51cbSPeter Avalostest that succeeds causes the file type to be printed.
38327e51cbSPeter Avalos.Pp
39327e51cbSPeter AvalosThe type printed will usually contain one of the words
40327e51cbSPeter Avalos.Em text
41327e51cbSPeter Avalos(the file contains only
42327e51cbSPeter Avalosprinting characters and a few common control
43327e51cbSPeter Avaloscharacters and is probably safe to read on an
44327e51cbSPeter Avalos.Dv ASCII
45327e51cbSPeter Avalosterminal),
46327e51cbSPeter Avalos.Em executable
47327e51cbSPeter Avalos(the file contains the result of compiling a program
48327e51cbSPeter Avalosin a form understandable to some
49327e51cbSPeter Avalos.Dv UNIX
50327e51cbSPeter Avaloskernel or another),
51327e51cbSPeter Avalosor
52327e51cbSPeter Avalos.Em data
53327e51cbSPeter Avalosmeaning anything else (data is usually
54327e51cbSPeter Avalos.Sq binary
55327e51cbSPeter Avalosor non-printable).
56327e51cbSPeter AvalosExceptions are well-known file formats (core files, tar archives)
57327e51cbSPeter Avalosthat are known to contain binary data.
5879343712SPeter AvalosWhen modifying magic files or the program itself, make sure to
59327e51cbSPeter Avalos.Em "preserve these keywords" .
6079343712SPeter AvalosUsers depend on knowing that all the readable files in a directory
61327e51cbSPeter Avaloshave the word
6279343712SPeter Avalos.Sq text
63327e51cbSPeter Avalosprinted.
64327e51cbSPeter AvalosDon't do as Berkeley did and change
6579343712SPeter Avalos.Sq shell commands text
66327e51cbSPeter Avalosto
6779343712SPeter Avalos.Sq shell script .
68327e51cbSPeter Avalos.Pp
69327e51cbSPeter AvalosThe filesystem tests are based on examining the return from a
70327e51cbSPeter Avalos.Xr stat 2
71327e51cbSPeter Avalossystem call.
72327e51cbSPeter AvalosThe program checks to see if the file is empty,
73327e51cbSPeter Avalosor if it's some sort of special file.
74327e51cbSPeter AvalosAny known file types appropriate to the system you are running on
75327e51cbSPeter Avalos(sockets, symbolic links, or named pipes (FIFOs) on those systems that
76327e51cbSPeter Avalosimplement them)
77327e51cbSPeter Avalosare intuited if they are defined in
78327e51cbSPeter Avalosthe system header file
79327e51cbSPeter Avalos.In sys/stat.h .
80327e51cbSPeter Avalos.Pp
8179343712SPeter AvalosThe magic tests are used to check for files with data in
82327e51cbSPeter Avalosparticular fixed formats.
83327e51cbSPeter AvalosThe canonical example of this is a binary executable (compiled program)
84327e51cbSPeter Avalos.Dv a.out
85327e51cbSPeter Avalosfile, whose format is defined in
86327e51cbSPeter Avalos.In elf.h ,
87327e51cbSPeter Avalos.In a.out.h
88327e51cbSPeter Avalosand possibly
89327e51cbSPeter Avalos.In exec.h
90327e51cbSPeter Avalosin the standard include directory.
91327e51cbSPeter AvalosThese files have a
92327e51cbSPeter Avalos.Sq "magic number"
93327e51cbSPeter Avalosstored in a particular place
94327e51cbSPeter Avalosnear the beginning of the file that tells the
95327e51cbSPeter Avalos.Dv UNIX operating system
96327e51cbSPeter Avalosthat the file is a binary executable, and which of several types thereof.
97327e51cbSPeter AvalosThe concept of a
9879343712SPeter Avalos.Sq "magic"
99327e51cbSPeter Avaloshas been applied by extension to data files.
100327e51cbSPeter AvalosAny file with some invariant identifier at a small fixed
101327e51cbSPeter Avalosoffset into the file can usually be described in this way.
102327e51cbSPeter AvalosThe information identifying these files is read from the compiled
103327e51cbSPeter Avalosmagic file
104327e51cbSPeter Avalos.Pa __MAGIC__.mgc ,
10579343712SPeter Avalosor the files in the directory
106327e51cbSPeter Avalos.Pa __MAGIC__
107e4d4ce0cSPeter Avalosif the compiled file does not exist.
108e4d4ce0cSPeter AvalosIn addition, if
10979343712SPeter Avalos.Pa $HOME/.magic.mgc
110327e51cbSPeter Avalosor
111327e51cbSPeter Avalos.Pa $HOME/.magic
11279343712SPeter Avalosexists, it will be used in preference to the system magic files.
113327e51cbSPeter Avalos.Pp
114327e51cbSPeter AvalosIf a file does not match any of the entries in the magic file,
115327e51cbSPeter Avalosit is examined to see if it seems to be a text file.
116327e51cbSPeter AvalosASCII, ISO-8859-x, non-ISO 8-bit extended-ASCII character sets
117327e51cbSPeter Avalos(such as those used on Macintosh and IBM PC systems),
118327e51cbSPeter AvalosUTF-8-encoded Unicode, UTF-16-encoded Unicode, and EBCDIC
119327e51cbSPeter Avaloscharacter sets can be distinguished by the different
120327e51cbSPeter Avalosranges and sequences of bytes that constitute printable text
121327e51cbSPeter Avalosin each set.
122327e51cbSPeter AvalosIf a file passes any of these tests, its character set is reported.
123327e51cbSPeter AvalosASCII, ISO-8859-x, UTF-8, and extended-ASCII files are identified
124327e51cbSPeter Avalosas
12579343712SPeter Avalos.Sq text
126327e51cbSPeter Avalosbecause they will be mostly readable on nearly any terminal;
127327e51cbSPeter AvalosUTF-16 and EBCDIC are only
12879343712SPeter Avalos.Sq character data
129327e51cbSPeter Avalosbecause, while
130327e51cbSPeter Avalosthey contain text, it is text that will require translation
131327e51cbSPeter Avalosbefore it can be read.
132327e51cbSPeter AvalosIn addition,
133327e51cbSPeter Avalos.Nm
134327e51cbSPeter Avaloswill attempt to determine other characteristics of text-type files.
135327e51cbSPeter AvalosIf the lines of a file are terminated by CR, CRLF, or NEL, instead
136327e51cbSPeter Avalosof the Unix-standard LF, this will be reported.
137327e51cbSPeter AvalosFiles that contain embedded escape sequences or overstriking
138327e51cbSPeter Avaloswill also be identified.
139327e51cbSPeter Avalos.Pp
140327e51cbSPeter AvalosOnce
141327e51cbSPeter Avalos.Nm
142327e51cbSPeter Avaloshas determined the character set used in a text-type file,
143327e51cbSPeter Avalosit will
144327e51cbSPeter Avalosattempt to determine in what language the file is written.
14579343712SPeter AvalosThe language tests look for particular strings (cf.
146327e51cbSPeter Avalos.In names.h
14779343712SPeter Avalos) that can appear anywhere in the first few blocks of a file.
148327e51cbSPeter AvalosFor example, the keyword
149327e51cbSPeter Avalos.Em .br
150327e51cbSPeter Avalosindicates that the file is most likely a
151327e51cbSPeter Avalos.Xr troff 1
152327e51cbSPeter Avalosinput file, just as the keyword
153327e51cbSPeter Avalos.Em struct
154327e51cbSPeter Avalosindicates a C program.
155327e51cbSPeter AvalosThese tests are less reliable than the previous
156327e51cbSPeter Avalostwo groups, so they are performed last.
157327e51cbSPeter AvalosThe language test routines also test for some miscellany
158327e51cbSPeter Avalos(such as
159327e51cbSPeter Avalos.Xr tar 1
160327e51cbSPeter Avalosarchives).
161327e51cbSPeter Avalos.Pp
162327e51cbSPeter AvalosAny file that cannot be identified as having been written
16379343712SPeter Avalosin any of the character sets listed above is simply said to be
16479343712SPeter Avalos.Sq data .
165327e51cbSPeter Avalos.Sh OPTIONS
166327e51cbSPeter Avalos.Bl -tag -width indent
167327e51cbSPeter Avalos.It Fl b , -brief
168327e51cbSPeter AvalosDo not prepend filenames to output lines (brief mode).
169f72f8299SJan Lentfer.It Fl C , -compile
170f72f8299SJan LentferWrite a
171f72f8299SJan Lentfer.Pa magic.mgc
172f72f8299SJan Lentferoutput file that contains a pre-parsed version of the magic file or directory.
173327e51cbSPeter Avalos.It Fl c , -checking-printout
174327e51cbSPeter AvalosCause a checking printout of the parsed form of the magic file.
175327e51cbSPeter AvalosThis is usually used in conjunction with the
176327e51cbSPeter Avalos.Fl m
177327e51cbSPeter Avalosflag to debug a new magic file before installing it.
178327e51cbSPeter Avalos.It Fl e , -exclude Ar testname
179327e51cbSPeter AvalosExclude the test named in
180327e51cbSPeter Avalos.Ar testname
181e4d4ce0cSPeter Avalosfrom the list of tests made to determine the file type.
182e4d4ce0cSPeter AvalosValid test names are:
183f72f8299SJan Lentfer.Bl -tag -width compress
184327e51cbSPeter Avalos.It apptype
185327e51cbSPeter Avalos.Dv EMX
186327e51cbSPeter Avalosapplication type (only on EMX).
187e4d4ce0cSPeter Avalos.It ascii
18879343712SPeter AvalosVarious types of text files (this test will try to guess the text encoding, irrespective of the setting of the
18979343712SPeter Avalos.Sq encoding
19079343712SPeter Avalosoption).
19179343712SPeter Avalos.It encoding
19279343712SPeter AvalosDifferent text encodings for soft magic tests.
19379343712SPeter Avalos.It tokens
19479343712SPeter AvalosLooks for known tokens inside text files.
19579343712SPeter Avalos.It cdf
19679343712SPeter AvalosPrints details of Compound Document Files.
197327e51cbSPeter Avalos.It compress
19879343712SPeter AvalosChecks for, and looks inside, compressed files.
199327e51cbSPeter Avalos.It elf
20079343712SPeter AvalosPrints ELF file details.
201327e51cbSPeter Avalos.It soft
20279343712SPeter AvalosConsults magic files.
203327e51cbSPeter Avalos.It tar
20479343712SPeter AvalosExamines tar files.
205327e51cbSPeter Avalos.El
206f72f8299SJan Lentfer.It Fl F , -separator Ar separator
207f72f8299SJan LentferUse the specified string as the separator between the filename and the
208e4d4ce0cSPeter Avalosfile result returned.
209e4d4ce0cSPeter AvalosDefaults to
210f72f8299SJan Lentfer.Sq \&: .
211327e51cbSPeter Avalos.It Fl f , -files-from Ar namefile
212327e51cbSPeter AvalosRead the names of the files to be examined from
213327e51cbSPeter Avalos.Ar namefile
214327e51cbSPeter Avalos(one per line)
215327e51cbSPeter Avalosbefore the argument list.
216327e51cbSPeter AvalosEither
217327e51cbSPeter Avalos.Ar namefile
218327e51cbSPeter Avalosor at least one filename argument must be present;
219327e51cbSPeter Avalosto test the standard input, use
220327e51cbSPeter Avalos.Sq -
221327e51cbSPeter Avalosas a filename argument.
222327e51cbSPeter Avalos.It Fl h , -no-dereference
223327e51cbSPeter Avalosoption causes symlinks not to be followed
224e4d4ce0cSPeter Avalos(on systems that support symbolic links).
225e4d4ce0cSPeter AvalosThis is the default if the environment variable
226327e51cbSPeter Avalos.Dv POSIXLY_CORRECT
227327e51cbSPeter Avalosis not defined.
228327e51cbSPeter Avalos.It Fl i , -mime
229327e51cbSPeter AvalosCauses the file command to output mime type strings rather than the more
230e4d4ce0cSPeter Avalostraditional human readable ones.
231e4d4ce0cSPeter AvalosThus it may say
23279343712SPeter Avalos.Sq text/plain; charset=us-ascii
233327e51cbSPeter Avalosrather than
23479343712SPeter Avalos.Sq ASCII text .
235327e51cbSPeter AvalosIn order for this option to work, file changes the way
236327e51cbSPeter Avalosit handles files recognized by the command itself (such as many of the
237327e51cbSPeter Avalostext file types, directories etc), and makes use of an alternative
23879343712SPeter Avalos.Sq magic
239327e51cbSPeter Avalosfile.
24079343712SPeter Avalos(See the FILES section, below).
241327e51cbSPeter Avalos.It Fl -mime-type , -mime-encoding
242327e51cbSPeter AvalosLike
243327e51cbSPeter Avalos.Fl i ,
244327e51cbSPeter Avalosbut print only the specified element(s).
245327e51cbSPeter Avalos.It Fl k , -keep-going
246e4d4ce0cSPeter AvalosDon't stop at the first match, keep going.
247e4d4ce0cSPeter AvalosSubsequent matches will be
24879343712SPeter Avaloshave the string
24979343712SPeter Avalos.Sq "\[rs]012\- "
25079343712SPeter Avalosprepended.
25179343712SPeter Avalos(If you want a newline, see the
25279343712SPeter Avalos.Sq "\-r"
25379343712SPeter Avalosoption.)
254e4d4ce0cSPeter Avalos.It Fl l , -list
255e4d4ce0cSPeter AvalosPrint information about the strength of each magic pattern.
256327e51cbSPeter Avalos.It Fl L , -dereference
257327e51cbSPeter Avalosoption causes symlinks to be followed, as the like-named option in
258327e51cbSPeter Avalos.Xr ls 1
259327e51cbSPeter Avalos(on systems that support symbolic links).
260327e51cbSPeter AvalosThis is the default if the environment variable
261327e51cbSPeter Avalos.Dv POSIXLY_CORRECT
262327e51cbSPeter Avalosis defined.
263e4d4ce0cSPeter Avalos.It Fl l
264e4d4ce0cSPeter AvalosShows sorted patterns list in the order which is used for the matching.
265f72f8299SJan Lentfer.It Fl m , -magic-file Ar magicfiles
26679343712SPeter AvalosSpecify an alternate list of files and directories containing magic.
26779343712SPeter AvalosThis can be a single item, or a colon-separated list.
26879343712SPeter AvalosIf a compiled magic file is found alongside a file or directory, it will be used instead.
269f72f8299SJan Lentfer.It Fl N , -no-pad
270f72f8299SJan LentferDon't pad filenames so that they align in the output.
271327e51cbSPeter Avalos.It Fl n , -no-buffer
272327e51cbSPeter AvalosForce stdout to be flushed after checking each file.
273327e51cbSPeter AvalosThis is only useful if checking a list of files.
274327e51cbSPeter AvalosIt is intended to be used by programs that want filetype output from a pipe.
275327e51cbSPeter Avalos.It Fl p , -preserve-date
276327e51cbSPeter AvalosOn systems that support
277327e51cbSPeter Avalos.Xr utime 2
278327e51cbSPeter Avalosor
279327e51cbSPeter Avalos.Xr utimes 2 ,
280327e51cbSPeter Avalosattempt to preserve the access time of files analyzed, to pretend that
281327e51cbSPeter Avalos.Nm
282327e51cbSPeter Avalosnever read them.
283327e51cbSPeter Avalos.It Fl r , -raw
284327e51cbSPeter AvalosDon't translate unprintable characters to \eooo.
285327e51cbSPeter AvalosNormally
286327e51cbSPeter Avalos.Nm
287327e51cbSPeter Avalostranslates unprintable characters to their octal representation.
288327e51cbSPeter Avalos.It Fl s , -special-files
289327e51cbSPeter AvalosNormally,
290327e51cbSPeter Avalos.Nm
291327e51cbSPeter Avalosonly attempts to read and determine the type of argument files which
292327e51cbSPeter Avalos.Xr stat 2
293327e51cbSPeter Avalosreports are ordinary files.
294327e51cbSPeter AvalosThis prevents problems, because reading special files may have peculiar
295327e51cbSPeter Avalosconsequences.
296327e51cbSPeter AvalosSpecifying the
297327e51cbSPeter Avalos.Fl s
298327e51cbSPeter Avalosoption causes
299327e51cbSPeter Avalos.Nm
300327e51cbSPeter Avalosto also read argument files which are block or character special files.
301327e51cbSPeter AvalosThis is useful for determining the filesystem types of the data in raw
302327e51cbSPeter Avalosdisk partitions, which are block special files.
303327e51cbSPeter AvalosThis option also causes
304327e51cbSPeter Avalos.Nm
305327e51cbSPeter Avalosto disregard the file size as reported by
306327e51cbSPeter Avalos.Xr stat 2
307327e51cbSPeter Avalossince on some systems it reports a zero size for raw disk partitions.
308327e51cbSPeter Avalos.It Fl v , -version
309327e51cbSPeter AvalosPrint the version of the program and exit.
310327e51cbSPeter Avalos.It Fl z , -uncompress
311327e51cbSPeter AvalosTry to look inside compressed files.
312327e51cbSPeter Avalos.It Fl 0 , -print0
313327e51cbSPeter AvalosOutput a null character
314327e51cbSPeter Avalos.Sq \e0
315e4d4ce0cSPeter Avalosafter the end of the filename.
316e4d4ce0cSPeter AvalosNice to
317327e51cbSPeter Avalos.Xr cut 1
318e4d4ce0cSPeter Avalosthe output.
319e4d4ce0cSPeter AvalosThis does not affect the separator which is still printed.
320327e51cbSPeter Avalos.It Fl -help
321327e51cbSPeter AvalosPrint a help message and exit.
322327e51cbSPeter Avalos.El
323327e51cbSPeter Avalos.Sh FILES
32479343712SPeter Avalos.Bl -tag -width __MAGIC__.mgc -compact
325327e51cbSPeter Avalos.It Pa __MAGIC__.mgc
32679343712SPeter AvalosDefault compiled list of magic.
327327e51cbSPeter Avalos.It Pa __MAGIC__
32879343712SPeter AvalosDirectory containing default magic files.
329327e51cbSPeter Avalos.El
330327e51cbSPeter Avalos.Sh ENVIRONMENT
331327e51cbSPeter AvalosThe environment variable
332327e51cbSPeter Avalos.Dv MAGIC
33379343712SPeter Avaloscan be used to set the default magic file name.
334327e51cbSPeter AvalosIf that variable is set, then
335327e51cbSPeter Avalos.Nm
336327e51cbSPeter Avaloswill not attempt to open
337327e51cbSPeter Avalos.Pa $HOME/.magic .
338327e51cbSPeter Avalos.Nm
339327e51cbSPeter Avalosadds
34079343712SPeter Avalos.Sq .mgc
341327e51cbSPeter Avalosto the value of this variable as appropriate.
342e4d4ce0cSPeter AvalosHowever,
343e4d4ce0cSPeter Avalos.Pa file
344e4d4ce0cSPeter Avaloshas to exist in order for
345e4d4ce0cSPeter Avalos.Pa file.mime
346e4d4ce0cSPeter Avalosto be considered.
347327e51cbSPeter AvalosThe environment variable
348327e51cbSPeter Avalos.Dv POSIXLY_CORRECT
34979343712SPeter Avaloscontrols (on systems that support symbolic links), whether
350327e51cbSPeter Avalos.Nm
351e4d4ce0cSPeter Avaloswill attempt to follow symlinks or not.
352e4d4ce0cSPeter AvalosIf set, then
353327e51cbSPeter Avalos.Nm
354e4d4ce0cSPeter Avalosfollows symlink, otherwise it does not.
355e4d4ce0cSPeter AvalosThis is also controlled by the
356327e51cbSPeter Avalos.Fl L
357327e51cbSPeter Avalosand
358327e51cbSPeter Avalos.Fl h
359327e51cbSPeter Avalosoptions.
360327e51cbSPeter Avalos.Sh SEE ALSO
361327e51cbSPeter Avalos.Xr magic __FSECTION__ ,
362327e51cbSPeter Avalos.Xr strings 1 ,
363327e51cbSPeter Avalos.Xr od 1 ,
36479343712SPeter Avalos.Xr hexdump 1 ,
36579343712SPeter Avalos.Xr file 1posix
366327e51cbSPeter Avalos.Sh STANDARDS CONFORMANCE
367327e51cbSPeter AvalosThis program is believed to exceed the System V Interface Definition
368327e51cbSPeter Avalosof FILE(CMD), as near as one can determine from the vague language
369327e51cbSPeter Avaloscontained therein.
370327e51cbSPeter AvalosIts behavior is mostly compatible with the System V program of the same name.
371327e51cbSPeter AvalosThis version knows more magic, however, so it will produce
372327e51cbSPeter Avalosdifferent (albeit more accurate) output in many cases.
373327e51cbSPeter Avalos.\" URL: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html
374327e51cbSPeter Avalos.Pp
375327e51cbSPeter AvalosThe one significant difference
376327e51cbSPeter Avalosbetween this version and System V
377327e51cbSPeter Avalosis that this version treats any white space
378327e51cbSPeter Avalosas a delimiter, so that spaces in pattern strings must be escaped.
379327e51cbSPeter AvalosFor example,
380327e51cbSPeter Avalos.Bd -literal -offset indent
381327e51cbSPeter Avalos>10	string	language impress\       (imPRESS data)
382327e51cbSPeter Avalos.Ed
383327e51cbSPeter Avalos.Pp
384327e51cbSPeter Avalosin an existing magic file would have to be changed to
385327e51cbSPeter Avalos.Bd -literal -offset indent
386327e51cbSPeter Avalos>10	string	language\e impress	(imPRESS data)
387327e51cbSPeter Avalos.Ed
388327e51cbSPeter Avalos.Pp
389327e51cbSPeter AvalosIn addition, in this version, if a pattern string contains a backslash,
390327e51cbSPeter Avalosit must be escaped.
391327e51cbSPeter AvalosFor example
392327e51cbSPeter Avalos.Bd -literal -offset indent
393327e51cbSPeter Avalos0	string		\ebegindata	Andrew Toolkit document
394327e51cbSPeter Avalos.Ed
395327e51cbSPeter Avalos.Pp
396327e51cbSPeter Avalosin an existing magic file would have to be changed to
397327e51cbSPeter Avalos.Bd -literal -offset indent
398327e51cbSPeter Avalos0	string		\e\ebegindata	Andrew Toolkit document
399327e51cbSPeter Avalos.Ed
400327e51cbSPeter Avalos.Pp
401327e51cbSPeter AvalosSunOS releases 3.2 and later from Sun Microsystems include a
402327e51cbSPeter Avalos.Nm
403327e51cbSPeter Avaloscommand derived from the System V one, but with some extensions.
404327e51cbSPeter AvalosMy version differs from Sun's only in minor ways.
405327e51cbSPeter AvalosIt includes the extension of the
406327e51cbSPeter Avalos.Sq &
407327e51cbSPeter Avalosoperator, used as,
408327e51cbSPeter Avalosfor example,
409327e51cbSPeter Avalos.Bd -literal -offset indent
410327e51cbSPeter Avalos>16	long&0x7fffffff	>0		not stripped
411327e51cbSPeter Avalos.Ed
412327e51cbSPeter Avalos.Sh MAGIC DIRECTORY
413327e51cbSPeter AvalosThe magic file entries have been collected from various sources,
414327e51cbSPeter Avalosmainly USENET, and contributed by various authors.
415327e51cbSPeter AvalosChristos Zoulas (address below) will collect additional
416327e51cbSPeter Avalosor corrected magic file entries.
417327e51cbSPeter AvalosA consolidation of magic file entries
418327e51cbSPeter Avaloswill be distributed periodically.
419327e51cbSPeter Avalos.Pp
420327e51cbSPeter AvalosThe order of entries in the magic file is significant.
421327e51cbSPeter AvalosDepending on what system you are using, the order that
422327e51cbSPeter Avalosthey are put together may be incorrect.
423327e51cbSPeter AvalosIf your old
424327e51cbSPeter Avalos.Nm
425327e51cbSPeter Avaloscommand uses a magic file,
426327e51cbSPeter Avaloskeep the old magic file around for comparison purposes
427327e51cbSPeter Avalos(rename it to
428327e51cbSPeter Avalos.Pa __MAGIC__.orig ).
429327e51cbSPeter Avalos.Sh EXAMPLES
430327e51cbSPeter Avalos.Bd -literal -offset indent
431327e51cbSPeter Avalos$ file file.c file /dev/{wd0a,hda}
432327e51cbSPeter Avalosfile.c:   C program text
433327e51cbSPeter Avalosfile:     ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
434327e51cbSPeter Avalos          dynamically linked (uses shared libs), stripped
435327e51cbSPeter Avalos/dev/wd0a: block special (0/0)
436327e51cbSPeter Avalos/dev/hda: block special (3/0)
437327e51cbSPeter Avalos
438327e51cbSPeter Avalos$ file -s /dev/wd0{b,d}
439327e51cbSPeter Avalos/dev/wd0b: data
440327e51cbSPeter Avalos/dev/wd0d: x86 boot sector
441327e51cbSPeter Avalos
442327e51cbSPeter Avalos$ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
443327e51cbSPeter Avalos/dev/hda:   x86 boot sector
444327e51cbSPeter Avalos/dev/hda1:  Linux/i386 ext2 filesystem
445327e51cbSPeter Avalos/dev/hda2:  x86 boot sector
446327e51cbSPeter Avalos/dev/hda3:  x86 boot sector, extended partition table
447327e51cbSPeter Avalos/dev/hda4:  Linux/i386 ext2 filesystem
448327e51cbSPeter Avalos/dev/hda5:  Linux/i386 swap file
449327e51cbSPeter Avalos/dev/hda6:  Linux/i386 swap file
450327e51cbSPeter Avalos/dev/hda7:  Linux/i386 swap file
451327e51cbSPeter Avalos/dev/hda8:  Linux/i386 swap file
452327e51cbSPeter Avalos/dev/hda9:  empty
453327e51cbSPeter Avalos/dev/hda10: empty
454327e51cbSPeter Avalos
455327e51cbSPeter Avalos$ file -i file.c file /dev/{wd0a,hda}
456327e51cbSPeter Avalosfile.c:      text/x-c
457327e51cbSPeter Avalosfile:        application/x-executable
458327e51cbSPeter Avalos/dev/hda:    application/x-not-regular-file
459327e51cbSPeter Avalos/dev/wd0a:   application/x-not-regular-file
460327e51cbSPeter Avalos
461327e51cbSPeter Avalos.Ed
462327e51cbSPeter Avalos.Sh HISTORY
463327e51cbSPeter AvalosThere has been a
464327e51cbSPeter Avalos.Nm
465327e51cbSPeter Avaloscommand in every
466327e51cbSPeter Avalos.Dv UNIX since at least Research Version 4
467327e51cbSPeter Avalos(man page dated November, 1973).
468327e51cbSPeter AvalosThe System V version introduced one significant major change:
46979343712SPeter Avalosthe external list of magic types.
470327e51cbSPeter AvalosThis slowed the program down slightly but made it a lot more flexible.
471327e51cbSPeter Avalos.Pp
472327e51cbSPeter AvalosThis program, based on the System V version,
473ff91a668SPeter Avaloswas written by Ian Darwin
474ff91a668SPeter Avalos.Aq ian@darwinsys.com
475327e51cbSPeter Avaloswithout looking at anybody else's source code.
476327e51cbSPeter Avalos.Pp
477327e51cbSPeter AvalosJohn Gilmore revised the code extensively, making it better than
478327e51cbSPeter Avalosthe first version.
479327e51cbSPeter AvalosGeoff Collyer found several inadequacies
480327e51cbSPeter Avalosand provided some magic file entries.
481ff91a668SPeter AvalosContributions by the `&' operator by Rob McMahon
482ff91a668SPeter Avalos.Aq cudcv@warwick.ac.uk ,
483ff91a668SPeter Avalos1989.
484327e51cbSPeter Avalos.Pp
485ff91a668SPeter AvalosGuy Harris
486ff91a668SPeter Avalos.Aq guy@netapp.com
487ff91a668SPeter Avalosmade many changes from 1993 to the present.
488327e51cbSPeter Avalos.Pp
489327e51cbSPeter AvalosPrimary development and maintenance from 1990 to the present by
490ff91a668SPeter AvalosChristos Zoulas
491ff91a668SPeter Avalos.Aq christos@astron.com .
492327e51cbSPeter Avalos.Pp
493ff91a668SPeter AvalosAltered by Chris Lowth
494ff91a668SPeter Avalos.Aq chris@lowth.com ,
495ff91a668SPeter Avalos2000: handle the
496327e51cbSPeter Avalos.Fl i
49779343712SPeter Avalosoption to output mime type strings, using an alternative
498327e51cbSPeter Avalosmagic file and internal logic.
499327e51cbSPeter Avalos.Pp
500ff91a668SPeter AvalosAltered by Eric Fischer
501ff91a668SPeter Avalos.Aq enf@pobox.com
502ff91a668SPeter AvalosJuly, 2000, to identify character codes and attempt to identify the languages
503327e51cbSPeter Avalosof non-ASCII files.
504327e51cbSPeter Avalos.Pp
505ff91a668SPeter AvalosAltered by Reuben Thomas
506ff91a668SPeter Avalos.Aq rrt@sc3d.org ,
507ff91a668SPeter Avalos2007-2011, to improve MIME support, merge MIME and non-MIME magic,
508ff91a668SPeter Avalossupport directories as well as files of magic, apply many bug fixes,
509ff91a668SPeter Avalosupdate and fix a lot of magic, improve the build system, improve the
510ff91a668SPeter Avalosdocumentation, and rewrite the Python bindings in pure Python.
51179343712SPeter Avalos.Pp
51279343712SPeter AvalosThe list of contributors to the
51379343712SPeter Avalos.Sq magic
51479343712SPeter Avalosdirectory (magic files)
51579343712SPeter Avalosis too long to include here.
516327e51cbSPeter AvalosYou know who you are; thank you.
51779343712SPeter AvalosMany contributors are listed in the source files.
518327e51cbSPeter Avalos.Sh LEGAL NOTICE
519327e51cbSPeter AvalosCopyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999.
520327e51cbSPeter AvalosCovered by the standard Berkeley Software Distribution copyright; see the file
521e4d4ce0cSPeter AvalosCOPYING in the source distribution.
522327e51cbSPeter Avalos.Pp
523327e51cbSPeter AvalosThe files
524327e51cbSPeter Avalos.Dv tar.h
525327e51cbSPeter Avalosand
526327e51cbSPeter Avalos.Dv is_tar.c
527327e51cbSPeter Avaloswere written by John Gilmore from his public-domain
528327e51cbSPeter Avalos.Xr tar 1
529327e51cbSPeter Avalosprogram, and are not covered by the above license.
530ff91a668SPeter Avalos.Sh RETURN CODE
531ff91a668SPeter Avalos.Nm
532ff91a668SPeter Avalosreturns 0 on success, and non-zero on error.
533327e51cbSPeter Avalos.Sh BUGS
53479343712SPeter Avalos.Pp
535e4d4ce0cSPeter AvalosPlease report bugs and send patches to the bug tracker at
536e4d4ce0cSPeter Avalos.Pa http://bugs.gw.com/
537e4d4ce0cSPeter Avalosor the mailing list at
538e4d4ce0cSPeter Avalos.Aq file@mx.gw.com .
539ff91a668SPeter Avalos.Sh TODO
540327e51cbSPeter Avalos.Pp
541ff91a668SPeter AvalosFix output so that tests for MIME and APPLE flags are not needed all
542ff91a668SPeter Avalosover the place, and actual output is only done in one place. This
543ff91a668SPeter Avalosneeds a design. Suggestion: push possible outputs on to a list, then
544ff91a668SPeter Avalospick the last-pushed (most specific, one hopes) value at the end, or
545ff91a668SPeter Avalosuse a default if the list is empty. This should not slow down evaluation.
546327e51cbSPeter Avalos.Pp
547ff91a668SPeter AvalosContinue to squash all magic bugs. See Debian BTS for a good source.
548327e51cbSPeter Avalos.Pp
549ff91a668SPeter AvalosStore arbitrarily long strings, for example for %s patterns, so that
550ff91a668SPeter Avalosthey can be printed out. Fixes Debian bug #271672. Would require more
551ff91a668SPeter Avaloscomplex store/load code in apprentice.
552327e51cbSPeter Avalos.Pp
553ff91a668SPeter AvalosAdd syntax for relative offsets after current level (Debian bug #466037).
554327e51cbSPeter Avalos.Pp
555ff91a668SPeter AvalosMake file -ki work, i.e. give multiple MIME types.
556327e51cbSPeter Avalos.Pp
557ff91a668SPeter AvalosAdd a zip library so we can peek inside Office2007 documents to
558ff91a668SPeter Avalosfigure out what they are.
559ff91a668SPeter Avalos.Pp
560ff91a668SPeter AvalosDon't complain when ~/.magic is not compiled.
561ff91a668SPeter Avalos.Pp
562ff91a668SPeter AvalosAdd an option to print URLs for the sources of the file descriptions.
563327e51cbSPeter Avalos.Sh AVAILABILITY
564327e51cbSPeter AvalosYou can obtain the original author's latest version by anonymous FTP
565ff91a668SPeter Avalosfrom
566327e51cbSPeter Avalos.Dv ftp.astron.com
567327e51cbSPeter Avalosin the directory
568327e51cbSPeter Avalos.Dv /pub/file/file-X.YZ.tar.gz
569