xref: /minix3/external/bsd/file/dist/doc/file.1 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: file.1,v 1.16 2015/01/02 21:15:32 christos Exp $
2ef01931fSBen Gras.\"
3*0a6a1f1dSLionel Sambuc.\" $File: file.man,v 1.111 2014/12/16 23:18:40 christos Exp $
4*0a6a1f1dSLionel Sambuc.Dd December 16, 2014
5ef01931fSBen Gras.Dt FILE 1
6ef01931fSBen Gras.Os
7ef01931fSBen Gras.Sh NAME
8ef01931fSBen Gras.Nm file
9ef01931fSBen Gras.Nd determine file type
10ef01931fSBen Gras.Sh SYNOPSIS
11ef01931fSBen Gras.Nm
12835f6802SDirk Vogt.Bk -words
13*0a6a1f1dSLionel Sambuc.Op Fl bcEhiklLNnprsvz0
14835f6802SDirk Vogt.Op Fl Fl apple
15835f6802SDirk Vogt.Op Fl Fl mime-encoding
16835f6802SDirk Vogt.Op Fl Fl mime-type
17835f6802SDirk Vogt.Op Fl e Ar testname
18ef01931fSBen Gras.Op Fl F Ar separator
19ef01931fSBen Gras.Op Fl f Ar namefile
20ef01931fSBen Gras.Op Fl m Ar magicfiles
21*0a6a1f1dSLionel Sambuc.Op Fl P Ar name=value
22835f6802SDirk Vogt.Ar
23835f6802SDirk Vogt.Ek
24ef01931fSBen Gras.Nm
25ef01931fSBen Gras.Fl C
26835f6802SDirk Vogt.Op Fl m Ar magicfiles
27ef01931fSBen Gras.Nm
28ef01931fSBen Gras.Op Fl Fl help
29ef01931fSBen Gras.Sh DESCRIPTION
30*0a6a1f1dSLionel SambucThis manual page documents version 5.22 of the
31ef01931fSBen Gras.Nm
32ef01931fSBen Grascommand.
33ef01931fSBen Gras.Pp
34ef01931fSBen Gras.Nm
35ef01931fSBen Grastests each argument in an attempt to classify it.
36ef01931fSBen GrasThere are three sets of tests, performed in this order:
37ef01931fSBen Grasfilesystem tests, magic tests, and language tests.
38ef01931fSBen GrasThe
39ef01931fSBen Gras.Em first
40ef01931fSBen Grastest that succeeds causes the file type to be printed.
41ef01931fSBen Gras.Pp
42ef01931fSBen GrasThe type printed will usually contain one of the words
43ef01931fSBen Gras.Em text
44ef01931fSBen Gras(the file contains only
45ef01931fSBen Grasprinting characters and a few common control
46ef01931fSBen Grascharacters and is probably safe to read on an
47ef01931fSBen Gras.Dv ASCII
48ef01931fSBen Grasterminal),
49ef01931fSBen Gras.Em executable
50ef01931fSBen Gras(the file contains the result of compiling a program
51ef01931fSBen Grasin a form understandable to some
52ef01931fSBen Gras.Tn UNIX
53ef01931fSBen Graskernel or another),
54ef01931fSBen Grasor
55ef01931fSBen Gras.Em data
56ef01931fSBen Grasmeaning anything else (data is usually
57ef01931fSBen Gras.Dq binary
58ef01931fSBen Grasor non-printable).
59ef01931fSBen GrasExceptions are well-known file formats (core files, tar archives)
60ef01931fSBen Grasthat are known to contain binary data.
61ef01931fSBen GrasWhen modifying magic files or the program itself, make sure to
62ef01931fSBen Gras.Em "preserve these keywords" .
63ef01931fSBen GrasUsers depend on knowing that all the readable files in a directory
64ef01931fSBen Grashave the word
65ef01931fSBen Gras.Dq text
66ef01931fSBen Grasprinted.
67ef01931fSBen GrasDon't do as Berkeley did and change
68ef01931fSBen Gras.Dq shell commands text
69ef01931fSBen Grasto
70ef01931fSBen Gras.Dq shell script .
71ef01931fSBen Gras.Pp
72ef01931fSBen GrasThe filesystem tests are based on examining the return from a
73ef01931fSBen Gras.Xr stat 2
74ef01931fSBen Grassystem call.
75ef01931fSBen GrasThe program checks to see if the file is empty,
76ef01931fSBen Grasor if it's some sort of special file.
77ef01931fSBen GrasAny known file types appropriate to the system you are running on
78ef01931fSBen Gras(sockets, symbolic links, or named pipes (FIFOs) on those systems that
79ef01931fSBen Grasimplement them)
80ef01931fSBen Grasare intuited if they are defined in the system header file
81ef01931fSBen Gras.In sys/stat.h .
82ef01931fSBen Gras.Pp
83ef01931fSBen GrasThe magic tests are used to check for files with data in
84ef01931fSBen Grasparticular fixed formats.
85ef01931fSBen GrasThe canonical example of this is a binary executable (compiled program)
86ef01931fSBen Gras.Dv a.out
87ef01931fSBen Grasfile, whose format is defined in
88ef01931fSBen Gras.In elf.h ,
89ef01931fSBen Gras.In a.out.h
90ef01931fSBen Grasand possibly
91ef01931fSBen Gras.In exec.h
92ef01931fSBen Grasin the standard include directory.
93ef01931fSBen GrasThese files have a
94ef01931fSBen Gras.Dq "magic number"
95ef01931fSBen Grasstored in a particular place
96ef01931fSBen Grasnear the beginning of the file that tells the
97ef01931fSBen Gras.Tn UNIX
98ef01931fSBen Grasoperating system
99ef01931fSBen Grasthat the file is a binary executable, and which of several types thereof.
100ef01931fSBen GrasThe concept of a
101ef01931fSBen Gras.Dq "magic"
102ef01931fSBen Grashas been applied by extension to data files.
103ef01931fSBen GrasAny file with some invariant identifier at a small fixed
104ef01931fSBen Grasoffset into the file can usually be described in this way.
105ef01931fSBen GrasThe information identifying these files is read from the compiled
106ef01931fSBen Grasmagic file
107ef01931fSBen Gras.Pa /usr/share/misc/magic.mgc ,
108ef01931fSBen Grasor the files in the directory
109ef01931fSBen Gras.Pa /usr/share/misc/magic
110ef01931fSBen Grasif the compiled file does not exist.
111ef01931fSBen GrasIn addition, if
112ef01931fSBen Gras.Pa $HOME/.magic.mgc
113ef01931fSBen Grasor
114ef01931fSBen Gras.Pa $HOME/.magic
115ef01931fSBen Grasexists, it will be used in preference to the system magic files.
116ef01931fSBen Gras.Pp
117ef01931fSBen GrasIf a file does not match any of the entries in the magic file,
118ef01931fSBen Grasit is examined to see if it seems to be a text file.
119ef01931fSBen GrasASCII, ISO-8859-x, non-ISO 8-bit extended-ASCII character sets
120ef01931fSBen Gras(such as those used on Macintosh and IBM PC systems),
121ef01931fSBen GrasUTF-8-encoded Unicode, UTF-16-encoded Unicode, and EBCDIC
122ef01931fSBen Grascharacter sets can be distinguished by the different
123ef01931fSBen Grasranges and sequences of bytes that constitute printable text
124ef01931fSBen Grasin each set.
125ef01931fSBen GrasIf a file passes any of these tests, its character set is reported.
126ef01931fSBen GrasASCII, ISO-8859-x, UTF-8, and extended-ASCII files are identified
127ef01931fSBen Grasas
128ef01931fSBen Gras.Dq text
129ef01931fSBen Grasbecause they will be mostly readable on nearly any terminal;
130ef01931fSBen GrasUTF-16 and EBCDIC are only
131ef01931fSBen Gras.Dq character data
132ef01931fSBen Grasbecause, while
133ef01931fSBen Grasthey contain text, it is text that will require translation
134ef01931fSBen Grasbefore it can be read.
135ef01931fSBen GrasIn addition,
136ef01931fSBen Gras.Nm
137ef01931fSBen Graswill attempt to determine other characteristics of text-type files.
138ef01931fSBen GrasIf the lines of a file are terminated by CR, CRLF, or NEL, instead
139ef01931fSBen Grasof the Unix-standard LF, this will be reported.
140ef01931fSBen GrasFiles that contain embedded escape sequences or overstriking
141ef01931fSBen Graswill also be identified.
142ef01931fSBen Gras.Pp
143ef01931fSBen GrasOnce
144ef01931fSBen Gras.Nm
145ef01931fSBen Grashas determined the character set used in a text-type file,
146ef01931fSBen Grasit will
147ef01931fSBen Grasattempt to determine in what language the file is written.
148ef01931fSBen GrasThe language tests look for particular strings (cf.
149ef01931fSBen Gras.In names.h )
150ef01931fSBen Grasthat can appear anywhere in the first few blocks of a file.
151ef01931fSBen GrasFor example, the keyword
152ef01931fSBen Gras.Em .br
153ef01931fSBen Grasindicates that the file is most likely a
154ef01931fSBen Gras.Xr troff 1
155ef01931fSBen Grasinput file, just as the keyword
156ef01931fSBen Gras.Em struct
157ef01931fSBen Grasindicates a C program.
158ef01931fSBen GrasThese tests are less reliable than the previous
159ef01931fSBen Grastwo groups, so they are performed last.
160ef01931fSBen GrasThe language test routines also test for some miscellany
161ef01931fSBen Gras(such as
162ef01931fSBen Gras.Xr tar 1
163ef01931fSBen Grasarchives).
164ef01931fSBen Gras.Pp
165ef01931fSBen GrasAny file that cannot be identified as having been written
166ef01931fSBen Grasin any of the character sets listed above is simply said to be
167ef01931fSBen Gras.Dq data .
168ef01931fSBen Gras.Sh OPTIONS
169ef01931fSBen Gras.Bl -tag -width indent
170*0a6a1f1dSLionel Sambuc.It Fl Fl apple
171*0a6a1f1dSLionel SambucCauses the file command to output the file type and creator code as
172*0a6a1f1dSLionel Sambucused by older MacOS versions. The code consists of eight letters,
173*0a6a1f1dSLionel Sambucthe first describing the file type, the latter the creator.
174ef01931fSBen Gras.It Fl b , Fl Fl brief
175ef01931fSBen GrasDo not prepend filenames to output lines (brief mode).
176835f6802SDirk Vogt.It Fl C , Fl Fl compile
177835f6802SDirk VogtWrite a
178835f6802SDirk Vogt.Pa magic.mgc
179835f6802SDirk Vogtoutput file that contains a pre-parsed version of the magic file or directory.
180ef01931fSBen Gras.It Fl c , Fl Fl checking-printout
181ef01931fSBen GrasCause a checking printout of the parsed form of the magic file.
182ef01931fSBen GrasThis is usually used in conjunction with the
183ef01931fSBen Gras.Fl m
184ef01931fSBen Grasflag to debug a new magic file before installing it.
185*0a6a1f1dSLionel Sambuc.It Fl E
186*0a6a1f1dSLionel SambucOn filesystem errors (file not found etc), instead of handling the error
187*0a6a1f1dSLionel Sambucas regular output as POSIX mandates and keep going, issue an error message
188*0a6a1f1dSLionel Sambucand exit.
189ef01931fSBen Gras.It Fl e , Fl Fl exclude Ar testname
190ef01931fSBen GrasExclude the test named in
191ef01931fSBen Gras.Ar testname
192ef01931fSBen Grasfrom the list of tests made to determine the file type.
193ef01931fSBen GrasValid test names are:
194ef01931fSBen Gras.Bl -tag -width compress
195ef01931fSBen Gras.It apptype
196ef01931fSBen Gras.Dv EMX
197ef01931fSBen Grasapplication type (only on EMX).
198835f6802SDirk Vogt.It ascii
199ef01931fSBen GrasVarious types of text files (this test will try to guess the text
200ef01931fSBen Grasencoding, irrespective of the setting of the
201835f6802SDirk Vogt.Sq encoding
202ef01931fSBen Grasoption).
203ef01931fSBen Gras.It encoding
204ef01931fSBen GrasDifferent text encodings for soft magic tests.
205ef01931fSBen Gras.It tokens
20608ff44c4SLionel SambucIgnored for backwards compatibility.
207ef01931fSBen Gras.It cdf
208ef01931fSBen GrasPrints details of Compound Document Files.
209ef01931fSBen Gras.It compress
210ef01931fSBen GrasChecks for, and looks inside, compressed files.
211ef01931fSBen Gras.It elf
212ef01931fSBen GrasPrints ELF file details.
213ef01931fSBen Gras.It soft
214ef01931fSBen GrasConsults magic files.
215ef01931fSBen Gras.It tar
216ef01931fSBen GrasExamines tar files.
217ef01931fSBen Gras.El
218ef01931fSBen Gras.It Fl F , Fl Fl separator Ar separator
219ef01931fSBen GrasUse the specified string as the separator between the filename and the
220ef01931fSBen Grasfile result returned.
221ef01931fSBen GrasDefaults to
222ef01931fSBen Gras.Sq \&: .
223ef01931fSBen Gras.It Fl f , Fl Fl files-from Ar namefile
224ef01931fSBen GrasRead the names of the files to be examined from
225ef01931fSBen Gras.Ar namefile
226ef01931fSBen Gras(one per line)
227ef01931fSBen Grasbefore the argument list.
228ef01931fSBen GrasEither
229ef01931fSBen Gras.Ar namefile
230ef01931fSBen Grasor at least one filename argument must be present;
231ef01931fSBen Grasto test the standard input, use
232ef01931fSBen Gras.Sq -
233ef01931fSBen Grasas a filename argument.
23408ff44c4SLionel SambucPlease note that
23508ff44c4SLionel Sambuc.Ar namefile
23608ff44c4SLionel Sambucis unwrapped and the enclosed filenames are processed when this option is
23708ff44c4SLionel Sambucencountered and before any further options processing is done.
23808ff44c4SLionel SambucThis allows one to process multiple lists of files with different command line
23908ff44c4SLionel Sambucarguments on the same
24008ff44c4SLionel Sambuc.Nm
24108ff44c4SLionel Sambucinvocation.
24208ff44c4SLionel SambucThus if you want to set the delimiter, you need to do it before you specify
24308ff44c4SLionel Sambucthe list of files, like:
24408ff44c4SLionel Sambuc.Dq Fl F Ar @ Fl f Ar namefile ,
24508ff44c4SLionel Sambucinstead of:
24608ff44c4SLionel Sambuc.Dq Fl f Ar namefile Fl F Ar @ .
247ef01931fSBen Gras.It Fl h , Fl Fl no-dereference
248835f6802SDirk Vogtoption causes symlinks not to be followed
249ef01931fSBen Gras(on systems that support symbolic links).
250ef01931fSBen GrasThis is the default if the environment variable
251835f6802SDirk Vogt.Dv POSIXLY_CORRECT
252ef01931fSBen Grasis not defined.
253ef01931fSBen Gras.It Fl i , Fl Fl mime
254835f6802SDirk VogtCauses the file command to output mime type strings rather than the more
255ef01931fSBen Grastraditional human readable ones.
256835f6802SDirk VogtThus it may say
257835f6802SDirk Vogt.Sq text/plain; charset=us-ascii
258ef01931fSBen Grasrather than
259ef01931fSBen Gras.Dq ASCII text .
260ef01931fSBen Gras.It Fl Fl mime-type , Fl Fl mime-encoding
261ef01931fSBen GrasLike
262ef01931fSBen Gras.Fl i ,
263ef01931fSBen Grasbut print only the specified element(s).
264ef01931fSBen Gras.It Fl k , Fl Fl keep-going
265ef01931fSBen GrasDon't stop at the first match, keep going.
266835f6802SDirk VogtSubsequent matches will be
267835f6802SDirk Vogthave the string
268835f6802SDirk Vogt.Sq "\[rs]012\- "
269ef01931fSBen Grasprepended.
270ef01931fSBen Gras(If you want a newline, see the
271ef01931fSBen Gras.Fl r
272ef01931fSBen Grasoption.)
27384d9c625SLionel SambucThe magic pattern with the highest strength (see the
27484d9c625SLionel Sambuc.Fl l
27584d9c625SLionel Sambucoption) comes first.
276835f6802SDirk Vogt.It Fl l , Fl Fl list
27784d9c625SLionel SambucShows a list of patterns and their strength sorted descending by
27884d9c625SLionel Sambuc.Xr magic 4
27984d9c625SLionel Sambucstrength
28084d9c625SLionel Sambucwhich is used for the matching (see also the
28184d9c625SLionel Sambuc.Fl k
28284d9c625SLionel Sambucoption).
283ef01931fSBen Gras.It Fl L , Fl Fl dereference
284835f6802SDirk Vogtoption causes symlinks to be followed, as the like-named option in
285ef01931fSBen Gras.Xr ls 1
286ef01931fSBen Gras(on systems that support symbolic links).
287ef01931fSBen GrasThis is the default if the environment variable
288ef01931fSBen Gras.Ev POSIXLY_CORRECT
289ef01931fSBen Grasis defined.
290835f6802SDirk Vogt.It Fl m , Fl Fl magic-file Ar magicfiles
291ef01931fSBen GrasSpecify an alternate list of files and directories containing magic.
292ef01931fSBen GrasThis can be a single item, or a colon-separated list.
293ef01931fSBen GrasIf a compiled magic file is found alongside a file or directory,
294ef01931fSBen Grasit will be used instead.
295ef01931fSBen Gras.It Fl N , Fl Fl no-pad
296ef01931fSBen GrasDon't pad filenames so that they align in the output.
297ef01931fSBen Gras.It Fl n , Fl Fl no-buffer
298ef01931fSBen GrasForce stdout to be flushed after checking each file.
299ef01931fSBen GrasThis is only useful if checking a list of files.
300ef01931fSBen GrasIt is intended to be used by programs that want filetype output from a pipe.
301ef01931fSBen Gras.It Fl p , Fl Fl preserve-date
302ef01931fSBen GrasOn systems that support
303ef01931fSBen Gras.Xr utime 3
304ef01931fSBen Grasor
305ef01931fSBen Gras.Xr utimes 2 ,
306ef01931fSBen Grasattempt to preserve the access time of files analyzed, to pretend that
307ef01931fSBen Gras.Nm
308ef01931fSBen Grasnever read them.
309*0a6a1f1dSLionel Sambuc.It Fl P , Fl Fl parameter Ar name=value
310*0a6a1f1dSLionel SambucSet various parameter limits.
311*0a6a1f1dSLionel Sambuc.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent
312*0a6a1f1dSLionel Sambuc.It Sy "Name" Ta Sy "Default" Ta Sy "Explanation"
313*0a6a1f1dSLionel Sambuc.It Li indir Ta 15 Ta recursion limit for indirect magic
314*0a6a1f1dSLionel Sambuc.It Li name Ta 30 Ta use count limit for name/use magic
315*0a6a1f1dSLionel Sambuc.It Li elf_notes Ta 256 Ta max ELF notes processed
316*0a6a1f1dSLionel Sambuc.It Li elf_phnum Ta 128 Ta max ELF program sections processed
317*0a6a1f1dSLionel Sambuc.It Li elf_shnum Ta 32768 Ta max ELF sections processed
318*0a6a1f1dSLionel Sambuc.El
319ef01931fSBen Gras.It Fl r , Fl Fl raw
320ef01931fSBen GrasDon't translate unprintable characters to \eooo.
321ef01931fSBen GrasNormally
322ef01931fSBen Gras.Nm
323ef01931fSBen Grastranslates unprintable characters to their octal representation.
324ef01931fSBen Gras.It Fl s , Fl Fl special-files
325ef01931fSBen GrasNormally,
326ef01931fSBen Gras.Nm
327ef01931fSBen Grasonly attempts to read and determine the type of argument files which
328ef01931fSBen Gras.Xr stat 2
329ef01931fSBen Grasreports are ordinary files.
330ef01931fSBen GrasThis prevents problems, because reading special files may have peculiar
331ef01931fSBen Grasconsequences.
332ef01931fSBen GrasSpecifying the
333ef01931fSBen Gras.Fl s
334ef01931fSBen Grasoption causes
335ef01931fSBen Gras.Nm
336ef01931fSBen Grasto also read argument files which are block or character special files.
337ef01931fSBen GrasThis is useful for determining the filesystem types of the data in raw
338ef01931fSBen Grasdisk partitions, which are block special files.
339ef01931fSBen GrasThis option also causes
340ef01931fSBen Gras.Nm
341ef01931fSBen Grasto disregard the file size as reported by
342ef01931fSBen Gras.Xr stat 2
343ef01931fSBen Grassince on some systems it reports a zero size for raw disk partitions.
344ef01931fSBen Gras.It Fl v , Fl Fl version
345ef01931fSBen GrasPrint the version of the program and exit.
346ef01931fSBen Gras.It Fl z , Fl Fl uncompress
347ef01931fSBen GrasTry to look inside compressed files.
348835f6802SDirk Vogt.It Fl 0 , Fl Fl print0
349835f6802SDirk VogtOutput a null character
350835f6802SDirk Vogt.Sq \e0
351835f6802SDirk Vogtafter the end of the filename.
352835f6802SDirk VogtNice to
353835f6802SDirk Vogt.Xr cut 1
354835f6802SDirk Vogtthe output.
355*0a6a1f1dSLionel SambucThis does not affect the separator, which is still printed.
356835f6802SDirk Vogt.It Fl -help
357835f6802SDirk VogtPrint a help message and exit.
358835f6802SDirk Vogt.El
359835f6802SDirk Vogt.Sh FILES
360835f6802SDirk Vogt.Bl -tag -width /usr/share/misc/magic.mgc -compact
361835f6802SDirk Vogt.It Pa /usr/share/misc/magic.mgc
362835f6802SDirk VogtDefault compiled list of magic.
363835f6802SDirk Vogt.It Pa /usr/share/misc/magic
364835f6802SDirk VogtDirectory containing default magic files.
365ef01931fSBen Gras.El
366ef01931fSBen Gras.Sh ENVIRONMENT
367ef01931fSBen GrasThe environment variable
368ef01931fSBen Gras.Ev MAGIC
369ef01931fSBen Grascan be used to set the default magic file name.
370ef01931fSBen GrasIf that variable is set, then
371ef01931fSBen Gras.Nm
372ef01931fSBen Graswill not attempt to open
373ef01931fSBen Gras.Pa $HOME/.magic .
374ef01931fSBen Gras.Nm
375ef01931fSBen Grasadds
376ef01931fSBen Gras.Dq Pa .mgc
377ef01931fSBen Grasto the value of this variable as appropriate.
378835f6802SDirk VogtHowever,
379835f6802SDirk Vogt.Pa file
380835f6802SDirk Vogthas to exist in order for
381835f6802SDirk Vogt.Pa file.mime
382835f6802SDirk Vogtto be considered.
383ef01931fSBen GrasThe environment variable
384ef01931fSBen Gras.Ev POSIXLY_CORRECT
385ef01931fSBen Grascontrols (on systems that support symbolic links), whether
386ef01931fSBen Gras.Nm
387ef01931fSBen Graswill attempt to follow symlinks or not.
388ef01931fSBen GrasIf set, then
389ef01931fSBen Gras.Nm
390ef01931fSBen Grasfollows symlink, otherwise it does not.
391ef01931fSBen GrasThis is also controlled by the
392ef01931fSBen Gras.Fl L
393ef01931fSBen Grasand
394ef01931fSBen Gras.Fl h
395ef01931fSBen Grasoptions.
396ef01931fSBen Gras.Sh SEE ALSO
397835f6802SDirk Vogt.Xr magic 5 ,
398ef01931fSBen Gras.Xr hexdump 1 ,
399ef01931fSBen Gras.Xr od 1 ,
400ef01931fSBen Gras.Xr strings 1 ,
401835f6802SDirk Vogt.Sh STANDARDS CONFORMANCE
402ef01931fSBen GrasThis program is believed to exceed the System V Interface Definition
403ef01931fSBen Grasof FILE(CMD), as near as one can determine from the vague language
404ef01931fSBen Grascontained therein.
405ef01931fSBen GrasIts behavior is mostly compatible with the System V program of the same name.
406ef01931fSBen GrasThis version knows more magic, however, so it will produce
407ef01931fSBen Grasdifferent (albeit more accurate) output in many cases.
408ef01931fSBen Gras.\" URL: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html
409ef01931fSBen Gras.Pp
410ef01931fSBen GrasThe one significant difference
411ef01931fSBen Grasbetween this version and System V
412ef01931fSBen Grasis that this version treats any white space
413ef01931fSBen Grasas a delimiter, so that spaces in pattern strings must be escaped.
414ef01931fSBen GrasFor example,
415ef01931fSBen Gras.Bd -literal -offset indent
416ef01931fSBen Gras\*[Gt]10	string	language impress\ 	(imPRESS data)
417ef01931fSBen Gras.Ed
418ef01931fSBen Gras.Pp
419ef01931fSBen Grasin an existing magic file would have to be changed to
420ef01931fSBen Gras.Bd -literal -offset indent
421ef01931fSBen Gras\*[Gt]10	string	language\e impress	(imPRESS data)
422ef01931fSBen Gras.Ed
423ef01931fSBen Gras.Pp
424ef01931fSBen GrasIn addition, in this version, if a pattern string contains a backslash,
425ef01931fSBen Grasit must be escaped.
426ef01931fSBen GrasFor example
427ef01931fSBen Gras.Bd -literal -offset indent
428ef01931fSBen Gras0	string		\ebegindata	Andrew Toolkit document
429ef01931fSBen Gras.Ed
430ef01931fSBen Gras.Pp
431ef01931fSBen Grasin an existing magic file would have to be changed to
432ef01931fSBen Gras.Bd -literal -offset indent
433ef01931fSBen Gras0	string		\e\ebegindata	Andrew Toolkit document
434ef01931fSBen Gras.Ed
435ef01931fSBen Gras.Pp
436ef01931fSBen GrasSunOS releases 3.2 and later from Sun Microsystems include a
437ef01931fSBen Gras.Nm
438ef01931fSBen Grascommand derived from the System V one, but with some extensions.
439ef01931fSBen GrasThis version differs from Sun's only in minor ways.
440ef01931fSBen GrasIt includes the extension of the
441ef01931fSBen Gras.Sq \*[Am]
442ef01931fSBen Grasoperator, used as,
443ef01931fSBen Grasfor example,
444ef01931fSBen Gras.Bd -literal -offset indent
445ef01931fSBen Gras\*[Gt]16	long\*[Am]0x7fffffff	\*[Gt]0		not stripped
446ef01931fSBen Gras.Ed
447ef01931fSBen Gras.Sh MAGIC DIRECTORY
448ef01931fSBen GrasThe magic file entries have been collected from various sources,
449ef01931fSBen Grasmainly USENET, and contributed by various authors.
450ef01931fSBen GrasChristos Zoulas (address below) will collect additional
451ef01931fSBen Grasor corrected magic file entries.
452ef01931fSBen GrasA consolidation of magic file entries
453ef01931fSBen Graswill be distributed periodically.
454ef01931fSBen Gras.Pp
455ef01931fSBen GrasThe order of entries in the magic file is significant.
456ef01931fSBen GrasDepending on what system you are using, the order that
457ef01931fSBen Grasthey are put together may be incorrect.
458ef01931fSBen GrasIf your old
459ef01931fSBen Gras.Nm
460ef01931fSBen Grascommand uses a magic file,
461ef01931fSBen Graskeep the old magic file around for comparison purposes
462ef01931fSBen Gras(rename it to
463ef01931fSBen Gras.Pa /usr/share/misc/magic.orig ) .
464835f6802SDirk Vogt.Sh EXAMPLES
465835f6802SDirk Vogt.Bd -literal -offset indent
466835f6802SDirk Vogt$ file file.c file /dev/{wd0a,hda}
467835f6802SDirk Vogtfile.c:   C program text
468835f6802SDirk Vogtfile:     ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
469835f6802SDirk Vogt          dynamically linked (uses shared libs), stripped
470835f6802SDirk Vogt/dev/wd0a: block special (0/0)
471835f6802SDirk Vogt/dev/hda: block special (3/0)
472835f6802SDirk Vogt
473835f6802SDirk Vogt$ file -s /dev/wd0{b,d}
474835f6802SDirk Vogt/dev/wd0b: data
475835f6802SDirk Vogt/dev/wd0d: x86 boot sector
476835f6802SDirk Vogt
477835f6802SDirk Vogt$ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
478835f6802SDirk Vogt/dev/hda:   x86 boot sector
479835f6802SDirk Vogt/dev/hda1:  Linux/i386 ext2 filesystem
480835f6802SDirk Vogt/dev/hda2:  x86 boot sector
481835f6802SDirk Vogt/dev/hda3:  x86 boot sector, extended partition table
482835f6802SDirk Vogt/dev/hda4:  Linux/i386 ext2 filesystem
483835f6802SDirk Vogt/dev/hda5:  Linux/i386 swap file
484835f6802SDirk Vogt/dev/hda6:  Linux/i386 swap file
485835f6802SDirk Vogt/dev/hda7:  Linux/i386 swap file
486835f6802SDirk Vogt/dev/hda8:  Linux/i386 swap file
487835f6802SDirk Vogt/dev/hda9:  empty
488835f6802SDirk Vogt/dev/hda10: empty
489835f6802SDirk Vogt
490835f6802SDirk Vogt$ file -i file.c file /dev/{wd0a,hda}
491835f6802SDirk Vogtfile.c:      text/x-c
492835f6802SDirk Vogtfile:        application/x-executable
493835f6802SDirk Vogt/dev/hda:    application/x-not-regular-file
494835f6802SDirk Vogt/dev/wd0a:   application/x-not-regular-file
495835f6802SDirk Vogt
496835f6802SDirk Vogt.Ed
497ef01931fSBen Gras.Sh HISTORY
498ef01931fSBen GrasThere has been a
499ef01931fSBen Gras.Nm
500ef01931fSBen Grascommand in every
501ef01931fSBen Gras.Dv UNIX since at least Research Version 4
502ef01931fSBen Gras(man page dated November, 1973).
503ef01931fSBen GrasThe System V version introduced one significant major change:
504ef01931fSBen Grasthe external list of magic types.
505ef01931fSBen GrasThis slowed the program down slightly but made it a lot more flexible.
506ef01931fSBen Gras.Pp
507ef01931fSBen GrasThis program, based on the System V version,
508ef01931fSBen Graswas written by Ian Darwin
509ef01931fSBen Gras.Aq ian@darwinsys.com
510ef01931fSBen Graswithout looking at anybody else's source code.
511ef01931fSBen Gras.Pp
512ef01931fSBen GrasJohn Gilmore revised the code extensively, making it better than
513ef01931fSBen Grasthe first version.
514ef01931fSBen GrasGeoff Collyer found several inadequacies
515ef01931fSBen Grasand provided some magic file entries.
516ef01931fSBen GrasContributions by the
517ef01931fSBen Gras.Sq \*[Am]
518835f6802SDirk Vogtoperator by Rob McMahon,
519835f6802SDirk Vogt.Aq cudcv@warwick.ac.uk ,
520835f6802SDirk Vogt1989.
521ef01931fSBen Gras.Pp
522835f6802SDirk VogtGuy Harris,
523835f6802SDirk Vogt.Aq guy@netapp.com ,
524835f6802SDirk Vogtmade many changes from 1993 to the present.
525835f6802SDirk Vogt1989.
526ef01931fSBen Gras.Pp
527ef01931fSBen GrasPrimary development and maintenance from 1990 to the present by
528ef01931fSBen GrasChristos Zoulas
529ef01931fSBen Gras.Aq christos@astron.com .
530ef01931fSBen Gras.Pp
531835f6802SDirk VogtAltered by Chris Lowth
532835f6802SDirk Vogt.Aq chris@lowth.com ,
533835f6802SDirk Vogt2000: handle the
534ef01931fSBen Gras.Fl i
535ef01931fSBen Grasoption to output mime type strings, using an alternative
536ef01931fSBen Grasmagic file and internal logic.
537ef01931fSBen Gras.Pp
538ef01931fSBen GrasAltered by Eric Fischer
539ef01931fSBen Gras.Aq enf@pobox.com ,
540ef01931fSBen GrasJuly, 2000,
541ef01931fSBen Grasto identify character codes and attempt to identify the languages
542ef01931fSBen Grasof non-ASCII files.
543ef01931fSBen Gras.Pp
544ef01931fSBen GrasAltered by Reuben Thomas
545ef01931fSBen Gras.Aq rrt@sc3d.org ,
546835f6802SDirk Vogt2007-2011, to improve MIME support, merge MIME and non-MIME magic,
547835f6802SDirk Vogtsupport directories as well as files of magic, apply many bug fixes,
548835f6802SDirk Vogtupdate and fix a lot of magic, improve the build system, improve the
549835f6802SDirk Vogtdocumentation, and rewrite the Python bindings in pure Python.
550ef01931fSBen Gras.Pp
551ef01931fSBen GrasThe list of contributors to the
552ef01931fSBen Gras.Sq magic
553ef01931fSBen Grasdirectory (magic files)
554ef01931fSBen Grasis too long to include here.
555ef01931fSBen GrasYou know who you are; thank you.
556ef01931fSBen GrasMany contributors are listed in the source files.
557ef01931fSBen Gras.Sh LEGAL NOTICE
558ef01931fSBen GrasCopyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999.
559ef01931fSBen GrasCovered by the standard Berkeley Software Distribution copyright; see the file
560835f6802SDirk VogtCOPYING in the source distribution.
561ef01931fSBen Gras.Pp
562ef01931fSBen GrasThe files
563ef01931fSBen Gras.Pa tar.h
564ef01931fSBen Grasand
565ef01931fSBen Gras.Pa is_tar.c
566ef01931fSBen Graswere written by John Gilmore from his public-domain
567ef01931fSBen Gras.Xr tar 1
568ef01931fSBen Grasprogram, and are not covered by the above license.
569835f6802SDirk Vogt.Sh RETURN CODE
570ef01931fSBen Gras.Nm
571835f6802SDirk Vogtreturns 0 on success, and non-zero on error.
572835f6802SDirk Vogt.Sh BUGS
573ef01931fSBen Gras.Pp
574835f6802SDirk VogtPlease report bugs and send patches to the bug tracker at
575835f6802SDirk Vogt.Pa http://bugs.gw.com/
576835f6802SDirk Vogtor the mailing list at
577*0a6a1f1dSLionel Sambuc.Aq file@mx.gw.com
578*0a6a1f1dSLionel Sambuc(visit
579*0a6a1f1dSLionel Sambuc.Pa http://mx.gw.com/mailman/listinfo/file
580*0a6a1f1dSLionel Sambucfirst to subscribe).
581835f6802SDirk Vogt.Sh TODO
582ef01931fSBen Gras.Pp
583835f6802SDirk VogtFix output so that tests for MIME and APPLE flags are not needed all
58484d9c625SLionel Sambucover the place, and actual output is only done in one place.
58584d9c625SLionel SambucThis needs a design.
58684d9c625SLionel SambucSuggestion: push possible outputs on to a list, then pick the
58784d9c625SLionel Sambuclast-pushed (most specific, one hopes) value at the end, or
58884d9c625SLionel Sambucuse a default if the list is empty.
58984d9c625SLionel SambucThis should not slow down evaluation.
590ef01931fSBen Gras.Pp
59184d9c625SLionel SambucContinue to squash all magic bugs.
59284d9c625SLionel SambucSee Debian BTS for a good source.
593ef01931fSBen Gras.Pp
594835f6802SDirk VogtStore arbitrarily long strings, for example for %s patterns, so that
59584d9c625SLionel Sambucthey can be printed out.
59684d9c625SLionel SambucFixes Debian bug #271672.
59784d9c625SLionel SambucWould require more complex store/load code in apprentice.
598ef01931fSBen Gras.Pp
599835f6802SDirk VogtAdd syntax for relative offsets after current level (Debian bug #466037).
600835f6802SDirk Vogt.Pp
601835f6802SDirk VogtMake file -ki work, i.e. give multiple MIME types.
602835f6802SDirk Vogt.Pp
603835f6802SDirk VogtAdd a zip library so we can peek inside Office2007 documents to
604835f6802SDirk Vogtfigure out what they are.
605835f6802SDirk Vogt.Pp
606835f6802SDirk VogtAdd an option to print URLs for the sources of the file descriptions.
60784d9c625SLionel Sambuc.Pp
60884d9c625SLionel SambucCombine script searches and add a way to map executable names to MIME
60984d9c625SLionel Sambuctypes (e.g. have a magic value for !:mime which causes the resulting
61084d9c625SLionel Sambucstring to be looked up in a table).
61184d9c625SLionel SambucThis would avoid adding the same magic repeatedly for each new
61284d9c625SLionel Sambuchash-bang interpreter.
61384d9c625SLionel Sambuc.Pp
61484d9c625SLionel SambucFix
61584d9c625SLionel Sambuc.Dq name
61684d9c625SLionel Sambucand
61784d9c625SLionel Sambuc.Dq use
61884d9c625SLionel Sambucto check for consistency at compile time (duplicate
61984d9c625SLionel Sambuc.Dq name ,
62084d9c625SLionel Sambuc.Dq use
62184d9c625SLionel Sambucpointing to undefined
62284d9c625SLionel Sambuc.Dq name
62384d9c625SLionel Sambuc).
62484d9c625SLionel SambucMake
62584d9c625SLionel Sambuc.Dq name
62684d9c625SLionel Sambuc/
62784d9c625SLionel Sambuc.Dq use
62884d9c625SLionel Sambucmore efficient by keeping a sorted list of names.
62984d9c625SLionel SambucSpecial-case ^ to flip endianness in the parser so that it does not
63084d9c625SLionel Sambuchave to be escaped, and document it.
631ef01931fSBen Gras.Sh AVAILABILITY
632ef01931fSBen GrasYou can obtain the original author's latest version by anonymous FTP
633ef01931fSBen Grason
634ef01931fSBen Gras.Pa ftp.astron.com
635ef01931fSBen Grasin the directory
636ef01931fSBen Gras.Pa /pub/file/file-X.YZ.tar.gz .
637