xref: /dflybsd-src/contrib/file/doc/file.man (revision c990e5ba296a6fc9cca0b70d4c36d67f474f8a61)
1*c990e5baSDaniel Fojt.\" $File: file.man,v 1.140 2020/06/07 17:41:07 christos Exp $
2*c990e5baSDaniel Fojt.Dd June 7, 2020
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
116fca56fbSSascha Wildner.Op Fl bcdEhiklLNnprsSvzZ0
12a96e001bSPeter Avalos.Op Fl Fl apple
13*c990e5baSDaniel Fojt.Op Fl Fl exclude-quiet
14c30bd091SSascha Wildner.Op Fl Fl extension
15a96e001bSPeter Avalos.Op Fl Fl mime-encoding
16a96e001bSPeter Avalos.Op Fl Fl mime-type
17f72f8299SJan Lentfer.Op Fl e Ar testname
18327e51cbSPeter Avalos.Op Fl F Ar separator
19f72f8299SJan Lentfer.Op Fl f Ar namefile
20327e51cbSPeter Avalos.Op Fl m Ar magicfiles
2182c5fa3eSPeter Avalos.Op Fl P Ar name=value
22f72f8299SJan Lentfer.Ar
23a96e001bSPeter Avalos.Ek
24327e51cbSPeter Avalos.Nm
25327e51cbSPeter Avalos.Fl C
26f72f8299SJan Lentfer.Op Fl m Ar magicfiles
2779343712SPeter Avalos.Nm
28a96e001bSPeter Avalos.Op Fl Fl help
29327e51cbSPeter Avalos.Sh DESCRIPTION
30327e51cbSPeter AvalosThis manual page documents version __VERSION__ of the
31327e51cbSPeter Avalos.Nm
32327e51cbSPeter Avaloscommand.
33327e51cbSPeter Avalos.Pp
34327e51cbSPeter Avalos.Nm
35327e51cbSPeter Avalostests each argument in an attempt to classify it.
36327e51cbSPeter AvalosThere are three sets of tests, performed in this order:
3779343712SPeter Avalosfilesystem tests, magic tests, and language tests.
38327e51cbSPeter AvalosThe
39327e51cbSPeter Avalos.Em first
40327e51cbSPeter Avalostest that succeeds causes the file type to be printed.
41327e51cbSPeter Avalos.Pp
42327e51cbSPeter AvalosThe type printed will usually contain one of the words
43327e51cbSPeter Avalos.Em text
44327e51cbSPeter Avalos(the file contains only
45327e51cbSPeter Avalosprinting characters and a few common control
46327e51cbSPeter Avaloscharacters and is probably safe to read on an
47327e51cbSPeter Avalos.Dv ASCII
48327e51cbSPeter Avalosterminal),
49327e51cbSPeter Avalos.Em executable
50327e51cbSPeter Avalos(the file contains the result of compiling a program
51327e51cbSPeter Avalosin a form understandable to some
52a96e001bSPeter Avalos.Tn UNIX
53327e51cbSPeter Avaloskernel or another),
54327e51cbSPeter Avalosor
55327e51cbSPeter Avalos.Em data
56327e51cbSPeter Avalosmeaning anything else (data is usually
57a96e001bSPeter Avalos.Dq binary
58327e51cbSPeter Avalosor non-printable).
59327e51cbSPeter AvalosExceptions are well-known file formats (core files, tar archives)
60327e51cbSPeter Avalosthat are known to contain binary data.
6179343712SPeter AvalosWhen modifying magic files or the program itself, make sure to
62327e51cbSPeter Avalos.Em "preserve these keywords" .
6379343712SPeter AvalosUsers depend on knowing that all the readable files in a directory
64327e51cbSPeter Avaloshave the word
65a96e001bSPeter Avalos.Dq text
66327e51cbSPeter Avalosprinted.
67327e51cbSPeter AvalosDon't do as Berkeley did and change
68a96e001bSPeter Avalos.Dq shell commands text
69327e51cbSPeter Avalosto
70a96e001bSPeter Avalos.Dq shell script .
71327e51cbSPeter Avalos.Pp
72327e51cbSPeter AvalosThe filesystem tests are based on examining the return from a
73327e51cbSPeter Avalos.Xr stat 2
74327e51cbSPeter Avalossystem call.
75327e51cbSPeter AvalosThe program checks to see if the file is empty,
76327e51cbSPeter Avalosor if it's some sort of special file.
77327e51cbSPeter AvalosAny known file types appropriate to the system you are running on
78327e51cbSPeter Avalos(sockets, symbolic links, or named pipes (FIFOs) on those systems that
79327e51cbSPeter Avalosimplement them)
80a96e001bSPeter Avalosare intuited if they are defined in the system header file
81327e51cbSPeter Avalos.In sys/stat.h .
82327e51cbSPeter Avalos.Pp
8379343712SPeter AvalosThe magic tests are used to check for files with data in
84327e51cbSPeter Avalosparticular fixed formats.
85327e51cbSPeter AvalosThe canonical example of this is a binary executable (compiled program)
86327e51cbSPeter Avalos.Dv a.out
87327e51cbSPeter Avalosfile, whose format is defined in
88327e51cbSPeter Avalos.In elf.h ,
89327e51cbSPeter Avalos.In a.out.h
90327e51cbSPeter Avalosand possibly
91327e51cbSPeter Avalos.In exec.h
92327e51cbSPeter Avalosin the standard include directory.
93327e51cbSPeter AvalosThese files have a
94a96e001bSPeter Avalos.Dq "magic number"
95327e51cbSPeter Avalosstored in a particular place
96327e51cbSPeter Avalosnear the beginning of the file that tells the
97a96e001bSPeter Avalos.Tn UNIX
98a96e001bSPeter Avalosoperating system
99327e51cbSPeter Avalosthat the file is a binary executable, and which of several types thereof.
100327e51cbSPeter AvalosThe concept of a
101a96e001bSPeter Avalos.Dq "magic"
102327e51cbSPeter Avaloshas been applied by extension to data files.
103327e51cbSPeter AvalosAny file with some invariant identifier at a small fixed
104327e51cbSPeter Avalosoffset into the file can usually be described in this way.
105327e51cbSPeter AvalosThe information identifying these files is read from the compiled
106327e51cbSPeter Avalosmagic file
107327e51cbSPeter Avalos.Pa __MAGIC__.mgc ,
10879343712SPeter Avalosor the files in the directory
109327e51cbSPeter Avalos.Pa __MAGIC__
110e4d4ce0cSPeter Avalosif the compiled file does not exist.
111e4d4ce0cSPeter AvalosIn addition, if
11279343712SPeter Avalos.Pa $HOME/.magic.mgc
113327e51cbSPeter Avalosor
114327e51cbSPeter Avalos.Pa $HOME/.magic
11579343712SPeter Avalosexists, it will be used in preference to the system magic files.
116327e51cbSPeter Avalos.Pp
117327e51cbSPeter AvalosIf a file does not match any of the entries in the magic file,
118327e51cbSPeter Avalosit is examined to see if it seems to be a text file.
119327e51cbSPeter AvalosASCII, ISO-8859-x, non-ISO 8-bit extended-ASCII character sets
120327e51cbSPeter Avalos(such as those used on Macintosh and IBM PC systems),
121327e51cbSPeter AvalosUTF-8-encoded Unicode, UTF-16-encoded Unicode, and EBCDIC
122327e51cbSPeter Avaloscharacter sets can be distinguished by the different
123327e51cbSPeter Avalosranges and sequences of bytes that constitute printable text
124327e51cbSPeter Avalosin each set.
125327e51cbSPeter AvalosIf a file passes any of these tests, its character set is reported.
126327e51cbSPeter AvalosASCII, ISO-8859-x, UTF-8, and extended-ASCII files are identified
127327e51cbSPeter Avalosas
128a96e001bSPeter Avalos.Dq text
129327e51cbSPeter Avalosbecause they will be mostly readable on nearly any terminal;
130327e51cbSPeter AvalosUTF-16 and EBCDIC are only
131a96e001bSPeter Avalos.Dq character data
132327e51cbSPeter Avalosbecause, while
133327e51cbSPeter Avalosthey contain text, it is text that will require translation
134327e51cbSPeter Avalosbefore it can be read.
135327e51cbSPeter AvalosIn addition,
136327e51cbSPeter Avalos.Nm
137327e51cbSPeter Avaloswill attempt to determine other characteristics of text-type files.
138327e51cbSPeter AvalosIf the lines of a file are terminated by CR, CRLF, or NEL, instead
139327e51cbSPeter Avalosof the Unix-standard LF, this will be reported.
140327e51cbSPeter AvalosFiles that contain embedded escape sequences or overstriking
141327e51cbSPeter Avaloswill also be identified.
142327e51cbSPeter Avalos.Pp
143327e51cbSPeter AvalosOnce
144327e51cbSPeter Avalos.Nm
145327e51cbSPeter Avaloshas determined the character set used in a text-type file,
146327e51cbSPeter Avalosit will
147327e51cbSPeter Avalosattempt to determine in what language the file is written.
14879343712SPeter AvalosThe language tests look for particular strings (cf.
149a96e001bSPeter Avalos.In names.h )
150a96e001bSPeter Avalosthat can appear anywhere in the first few blocks of a file.
151327e51cbSPeter AvalosFor example, the keyword
152327e51cbSPeter Avalos.Em .br
153327e51cbSPeter Avalosindicates that the file is most likely a
154327e51cbSPeter Avalos.Xr troff 1
155327e51cbSPeter Avalosinput file, just as the keyword
156327e51cbSPeter Avalos.Em struct
157327e51cbSPeter Avalosindicates a C program.
158327e51cbSPeter AvalosThese tests are less reliable than the previous
159327e51cbSPeter Avalostwo groups, so they are performed last.
160327e51cbSPeter AvalosThe language test routines also test for some miscellany
161327e51cbSPeter Avalos(such as
162327e51cbSPeter Avalos.Xr tar 1
1636fca56fbSSascha Wildnerarchives, JSON files).
164327e51cbSPeter Avalos.Pp
165327e51cbSPeter AvalosAny file that cannot be identified as having been written
16679343712SPeter Avalosin any of the character sets listed above is simply said to be
167a96e001bSPeter Avalos.Dq data .
168327e51cbSPeter Avalos.Sh OPTIONS
169327e51cbSPeter Avalos.Bl -tag -width indent
170e8af9738SPeter Avalos.It Fl Fl apple
171e8af9738SPeter AvalosCauses the file command to output the file type and creator code as
1726fca56fbSSascha Wildnerused by older MacOS versions.
1736fca56fbSSascha WildnerThe code consists of eight letters,
174e8af9738SPeter Avalosthe first describing the file type, the latter the creator.
1756fca56fbSSascha WildnerThis option works properly only for file formats that have the
1766fca56fbSSascha Wildnerapple-style output defined.
177a96e001bSPeter Avalos.It Fl b , Fl Fl brief
178327e51cbSPeter AvalosDo not prepend filenames to output lines (brief mode).
179a96e001bSPeter Avalos.It Fl C , Fl Fl compile
180f72f8299SJan LentferWrite a
181f72f8299SJan Lentfer.Pa magic.mgc
182f72f8299SJan Lentferoutput file that contains a pre-parsed version of the magic file or directory.
183a96e001bSPeter Avalos.It Fl c , Fl Fl checking-printout
184327e51cbSPeter AvalosCause a checking printout of the parsed form of the magic file.
185327e51cbSPeter AvalosThis is usually used in conjunction with the
186327e51cbSPeter Avalos.Fl m
187327e51cbSPeter Avalosflag to debug a new magic file before installing it.
188c30bd091SSascha Wildner.It Fl d
189c30bd091SSascha WildnerPrints internal debugging information to stderr.
190e8af9738SPeter Avalos.It Fl E
191e8af9738SPeter AvalosOn filesystem errors (file not found etc), instead of handling the error
192e8af9738SPeter Avalosas regular output as POSIX mandates and keep going, issue an error message
193e8af9738SPeter Avalosand exit.
194a96e001bSPeter Avalos.It Fl e , Fl Fl exclude Ar testname
195327e51cbSPeter AvalosExclude the test named in
196327e51cbSPeter Avalos.Ar testname
197e4d4ce0cSPeter Avalosfrom the list of tests made to determine the file type.
198e4d4ce0cSPeter AvalosValid test names are:
199f72f8299SJan Lentfer.Bl -tag -width compress
200327e51cbSPeter Avalos.It apptype
201327e51cbSPeter Avalos.Dv EMX
202327e51cbSPeter Avalosapplication type (only on EMX).
203e4d4ce0cSPeter Avalos.It ascii
204a96e001bSPeter AvalosVarious types of text files (this test will try to guess the text
205a96e001bSPeter Avalosencoding, irrespective of the setting of the
20679343712SPeter Avalos.Sq encoding
20779343712SPeter Avalosoption).
20879343712SPeter Avalos.It encoding
20979343712SPeter AvalosDifferent text encodings for soft magic tests.
21079343712SPeter Avalos.It tokens
2119f86ab30SPeter AvalosIgnored for backwards compatibility.
21279343712SPeter Avalos.It cdf
21379343712SPeter AvalosPrints details of Compound Document Files.
214327e51cbSPeter Avalos.It compress
21579343712SPeter AvalosChecks for, and looks inside, compressed files.
2166fca56fbSSascha Wildner.It csv
2176fca56fbSSascha WildnerChecks Comma Separated Value files.
218327e51cbSPeter Avalos.It elf
219c30bd091SSascha WildnerPrints ELF file details, provided soft magic tests are enabled and the
220c30bd091SSascha Wildnerelf magic is found.
2216fca56fbSSascha Wildner.It json
2226fca56fbSSascha WildnerExamines JSON (RFC-7159) files by parsing them for compliance.
223327e51cbSPeter Avalos.It soft
22479343712SPeter AvalosConsults magic files.
225327e51cbSPeter Avalos.It tar
2266fca56fbSSascha WildnerExamines tar files by verifying the checksum of the 512 byte tar header.
2276fca56fbSSascha WildnerExcluding this test can provide more detailed content description by using
2286fca56fbSSascha Wildnerthe soft magic method.
229c30bd091SSascha Wildner.It text
230c30bd091SSascha WildnerA synonym for
231c30bd091SSascha Wildner.Sq ascii .
232327e51cbSPeter Avalos.El
233*c990e5baSDaniel Fojt.It Fl Fl exclude-quiet
234*c990e5baSDaniel FojtLike
235*c990e5baSDaniel Fojt.Fl Fl exclude
236*c990e5baSDaniel Fojtbut ignore tests that
237*c990e5baSDaniel Fojt.Nm
238*c990e5baSDaniel Fojtdoes not know about.
239*c990e5baSDaniel FojtThis is intended for compatilibity with older versions of
240*c990e5baSDaniel Fojt.Nm .
241c30bd091SSascha Wildner.It Fl Fl extension
242c30bd091SSascha WildnerPrint a slash-separated list of valid extensions for the file type found.
243a96e001bSPeter Avalos.It Fl F , Fl Fl separator Ar separator
244f72f8299SJan LentferUse the specified string as the separator between the filename and the
245e4d4ce0cSPeter Avalosfile result returned.
246e4d4ce0cSPeter AvalosDefaults to
247f72f8299SJan Lentfer.Sq \&: .
248a96e001bSPeter Avalos.It Fl f , Fl Fl files-from Ar namefile
249327e51cbSPeter AvalosRead the names of the files to be examined from
250327e51cbSPeter Avalos.Ar namefile
251327e51cbSPeter Avalos(one per line)
252327e51cbSPeter Avalosbefore the argument list.
253327e51cbSPeter AvalosEither
254327e51cbSPeter Avalos.Ar namefile
255327e51cbSPeter Avalosor at least one filename argument must be present;
256327e51cbSPeter Avalosto test the standard input, use
257327e51cbSPeter Avalos.Sq -
258327e51cbSPeter Avalosas a filename argument.
2599f86ab30SPeter AvalosPlease note that
2609f86ab30SPeter Avalos.Ar namefile
2619f86ab30SPeter Avalosis unwrapped and the enclosed filenames are processed when this option is
2629f86ab30SPeter Avalosencountered and before any further options processing is done.
2639f86ab30SPeter AvalosThis allows one to process multiple lists of files with different command line
2649f86ab30SPeter Avalosarguments on the same
2659f86ab30SPeter Avalos.Nm
2669f86ab30SPeter Avalosinvocation.
2679f86ab30SPeter AvalosThus if you want to set the delimiter, you need to do it before you specify
2689f86ab30SPeter Avalosthe list of files, like:
2699f86ab30SPeter Avalos.Dq Fl F Ar @ Fl f Ar namefile ,
2709f86ab30SPeter Avalosinstead of:
2719f86ab30SPeter Avalos.Dq Fl f Ar namefile Fl F Ar @ .
272a96e001bSPeter Avalos.It Fl h , Fl Fl no-dereference
273327e51cbSPeter Avalosoption causes symlinks not to be followed
274e4d4ce0cSPeter Avalos(on systems that support symbolic links).
275e4d4ce0cSPeter AvalosThis is the default if the environment variable
276327e51cbSPeter Avalos.Dv POSIXLY_CORRECT
277327e51cbSPeter Avalosis not defined.
278a96e001bSPeter Avalos.It Fl i , Fl Fl mime
279327e51cbSPeter AvalosCauses the file command to output mime type strings rather than the more
280e4d4ce0cSPeter Avalostraditional human readable ones.
281e4d4ce0cSPeter AvalosThus it may say
28279343712SPeter Avalos.Sq text/plain; charset=us-ascii
283327e51cbSPeter Avalosrather than
284a96e001bSPeter Avalos.Dq ASCII text .
285a96e001bSPeter Avalos.It Fl Fl mime-type , Fl Fl mime-encoding
286327e51cbSPeter AvalosLike
287327e51cbSPeter Avalos.Fl i ,
288327e51cbSPeter Avalosbut print only the specified element(s).
289a96e001bSPeter Avalos.It Fl k , Fl Fl keep-going
290e4d4ce0cSPeter AvalosDon't stop at the first match, keep going.
291e4d4ce0cSPeter AvalosSubsequent matches will be
29279343712SPeter Avaloshave the string
29379343712SPeter Avalos.Sq "\[rs]012\- "
29479343712SPeter Avalosprepended.
29579343712SPeter Avalos(If you want a newline, see the
296a96e001bSPeter Avalos.Fl r
29779343712SPeter Avalosoption.)
298e8af9738SPeter AvalosThe magic pattern with the highest strength (see the
299e8af9738SPeter Avalos.Fl l
300e8af9738SPeter Avalosoption) comes first.
301a96e001bSPeter Avalos.It Fl l , Fl Fl list
302e8af9738SPeter AvalosShows a list of patterns and their strength sorted descending by
3036fca56fbSSascha Wildner.Xr magic __FSECTION__
304e8af9738SPeter Avalosstrength
305e8af9738SPeter Avaloswhich is used for the matching (see also the
306e8af9738SPeter Avalos.Fl k
307e8af9738SPeter Avalosoption).
308a96e001bSPeter Avalos.It Fl L , Fl Fl dereference
309327e51cbSPeter Avalosoption causes symlinks to be followed, as the like-named option in
310327e51cbSPeter Avalos.Xr ls 1
311327e51cbSPeter Avalos(on systems that support symbolic links).
312327e51cbSPeter AvalosThis is the default if the environment variable
313a96e001bSPeter Avalos.Ev POSIXLY_CORRECT
314327e51cbSPeter Avalosis defined.
315a96e001bSPeter Avalos.It Fl m , Fl Fl magic-file Ar magicfiles
31679343712SPeter AvalosSpecify an alternate list of files and directories containing magic.
31779343712SPeter AvalosThis can be a single item, or a colon-separated list.
318a96e001bSPeter AvalosIf a compiled magic file is found alongside a file or directory,
319a96e001bSPeter Avalosit will be used instead.
320a96e001bSPeter Avalos.It Fl N , Fl Fl no-pad
321f72f8299SJan LentferDon't pad filenames so that they align in the output.
322a96e001bSPeter Avalos.It Fl n , Fl Fl no-buffer
323327e51cbSPeter AvalosForce stdout to be flushed after checking each file.
324327e51cbSPeter AvalosThis is only useful if checking a list of files.
325327e51cbSPeter AvalosIt is intended to be used by programs that want filetype output from a pipe.
326a96e001bSPeter Avalos.It Fl p , Fl Fl preserve-date
327327e51cbSPeter AvalosOn systems that support
328a96e001bSPeter Avalos.Xr utime 3
329327e51cbSPeter Avalosor
330327e51cbSPeter Avalos.Xr utimes 2 ,
331327e51cbSPeter Avalosattempt to preserve the access time of files analyzed, to pretend that
332327e51cbSPeter Avalos.Nm
333327e51cbSPeter Avalosnever read them.
33482c5fa3eSPeter Avalos.It Fl P , Fl Fl parameter Ar name=value
33582c5fa3eSPeter AvalosSet various parameter limits.
336c30bd091SSascha Wildner.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent
33782c5fa3eSPeter Avalos.It Sy "Name" Ta Sy "Default" Ta Sy "Explanation"
338c30bd091SSascha Wildner.It Li bytes Ta 1048576 Ta max number of bytes to read from file
339*c990e5baSDaniel Fojt.It Li elf_notes Ta 256 Ta max ELF notes processed
340*c990e5baSDaniel Fojt.It Li elf_phnum Ta 2048 Ta max ELF program sections processed
341*c990e5baSDaniel Fojt.It Li elf_shnum Ta 32768 Ta max ELF sections processed
342*c990e5baSDaniel Fojt.It Li indir Ta 50 Ta recursion limit for indirect magic
343*c990e5baSDaniel Fojt.It Li name Ta 50 Ta use count limit for name/use magic
344*c990e5baSDaniel Fojt.It Li regex Ta 8192 Ta length limit for regex searches
34582c5fa3eSPeter Avalos.El
346a96e001bSPeter Avalos.It Fl r , Fl Fl raw
347327e51cbSPeter AvalosDon't translate unprintable characters to \eooo.
348327e51cbSPeter AvalosNormally
349327e51cbSPeter Avalos.Nm
350327e51cbSPeter Avalostranslates unprintable characters to their octal representation.
351a96e001bSPeter Avalos.It Fl s , Fl Fl special-files
352327e51cbSPeter AvalosNormally,
353327e51cbSPeter Avalos.Nm
354327e51cbSPeter Avalosonly attempts to read and determine the type of argument files which
355327e51cbSPeter Avalos.Xr stat 2
356327e51cbSPeter Avalosreports are ordinary files.
357327e51cbSPeter AvalosThis prevents problems, because reading special files may have peculiar
358327e51cbSPeter Avalosconsequences.
359327e51cbSPeter AvalosSpecifying the
360327e51cbSPeter Avalos.Fl s
361327e51cbSPeter Avalosoption causes
362327e51cbSPeter Avalos.Nm
363327e51cbSPeter Avalosto also read argument files which are block or character special files.
364327e51cbSPeter AvalosThis is useful for determining the filesystem types of the data in raw
365327e51cbSPeter Avalosdisk partitions, which are block special files.
366327e51cbSPeter AvalosThis option also causes
367327e51cbSPeter Avalos.Nm
368327e51cbSPeter Avalosto disregard the file size as reported by
369327e51cbSPeter Avalos.Xr stat 2
370327e51cbSPeter Avalossince on some systems it reports a zero size for raw disk partitions.
3716fca56fbSSascha Wildner.It Fl S , Fl Fl no-sandbox
3726fca56fbSSascha WildnerOn systems where libseccomp
3736fca56fbSSascha Wildner.Pa ( https://github.com/seccomp/libseccomp )
3746fca56fbSSascha Wildneris available, the
3756fca56fbSSascha Wildner.Fl S
3766fca56fbSSascha Wildnerflag disables sandboxing which is enabled by default.
3776fca56fbSSascha WildnerThis option is needed for file to execute external decompressing programs,
3786fca56fbSSascha Wildneri.e. when the
3796fca56fbSSascha Wildner.Fl z
3806fca56fbSSascha Wildnerflag is specified and the built-in decompressors are not available.
3816fca56fbSSascha WildnerOn systems where sandboxing is not available, this option has no effect.
382a96e001bSPeter Avalos.It Fl v , Fl Fl version
383327e51cbSPeter AvalosPrint the version of the program and exit.
384a96e001bSPeter Avalos.It Fl z , Fl Fl uncompress
385327e51cbSPeter AvalosTry to look inside compressed files.
386c30bd091SSascha Wildner.It Fl Z , Fl Fl uncompress-noreport
387c30bd091SSascha WildnerTry to look inside compressed files, but report information about the contents
388c30bd091SSascha Wildneronly not the compression.
389a96e001bSPeter Avalos.It Fl 0 , Fl Fl print0
390327e51cbSPeter AvalosOutput a null character
391327e51cbSPeter Avalos.Sq \e0
392e4d4ce0cSPeter Avalosafter the end of the filename.
393e4d4ce0cSPeter AvalosNice to
394327e51cbSPeter Avalos.Xr cut 1
395e4d4ce0cSPeter Avalosthe output.
396e8af9738SPeter AvalosThis does not affect the separator, which is still printed.
397c30bd091SSascha Wildner.Pp
398c30bd091SSascha WildnerIf this option is repeated more than once, then
399c30bd091SSascha Wildner.Nm
400c30bd091SSascha Wildnerprints just the filename followed by a NUL followed by the description
401c30bd091SSascha Wildner(or ERROR: text) followed by a second NUL for each entry.
402327e51cbSPeter Avalos.It Fl -help
403327e51cbSPeter AvalosPrint a help message and exit.
404327e51cbSPeter Avalos.El
405327e51cbSPeter Avalos.Sh ENVIRONMENT
406327e51cbSPeter AvalosThe environment variable
407a96e001bSPeter Avalos.Ev MAGIC
40879343712SPeter Avaloscan be used to set the default magic file name.
409327e51cbSPeter AvalosIf that variable is set, then
410327e51cbSPeter Avalos.Nm
411327e51cbSPeter Avaloswill not attempt to open
412327e51cbSPeter Avalos.Pa $HOME/.magic .
413327e51cbSPeter Avalos.Nm
414327e51cbSPeter Avalosadds
415a96e001bSPeter Avalos.Dq Pa .mgc
416327e51cbSPeter Avalosto the value of this variable as appropriate.
417327e51cbSPeter AvalosThe environment variable
418a96e001bSPeter Avalos.Ev POSIXLY_CORRECT
41979343712SPeter Avaloscontrols (on systems that support symbolic links), whether
420327e51cbSPeter Avalos.Nm
421e4d4ce0cSPeter Avaloswill attempt to follow symlinks or not.
422e4d4ce0cSPeter AvalosIf set, then
423327e51cbSPeter Avalos.Nm
424e4d4ce0cSPeter Avalosfollows symlink, otherwise it does not.
425e4d4ce0cSPeter AvalosThis is also controlled by the
426327e51cbSPeter Avalos.Fl L
427327e51cbSPeter Avalosand
428327e51cbSPeter Avalos.Fl h
429327e51cbSPeter Avalosoptions.
4306fca56fbSSascha Wildner.Sh FILES
4316fca56fbSSascha Wildner.Bl -tag -width __MAGIC__.mgc -compact
4326fca56fbSSascha Wildner.It Pa __MAGIC__.mgc
4336fca56fbSSascha WildnerDefault compiled list of magic.
4346fca56fbSSascha Wildner.It Pa __MAGIC__
4356fca56fbSSascha WildnerDirectory containing default magic files.
4366fca56fbSSascha Wildner.El
4376fca56fbSSascha Wildner.Sh EXIT STATUS
4386fca56fbSSascha Wildner.Nm
4396fca56fbSSascha Wildnerwill exit with
4406fca56fbSSascha Wildner.Dv 0
4416fca56fbSSascha Wildnerif the operation was successful or
4426fca56fbSSascha Wildner.Dv >0
4436fca56fbSSascha Wildnerif an error was encountered.
4446fca56fbSSascha WildnerThe following errors cause diagnostic messages, but don't affect the program
4456fca56fbSSascha Wildnerexit code (as POSIX requires), unless
4466fca56fbSSascha Wildner.Fl E
4476fca56fbSSascha Wildneris specified:
4486fca56fbSSascha Wildner.Bl -bullet -compact -offset indent
4496fca56fbSSascha Wildner.It
4506fca56fbSSascha WildnerA file cannot be found
4516fca56fbSSascha Wildner.It
4526fca56fbSSascha WildnerThere is no permission to read a file
4536fca56fbSSascha Wildner.It
4546fca56fbSSascha WildnerThe file type cannot be determined
4556fca56fbSSascha Wildner.El
4566fca56fbSSascha Wildner.Sh EXAMPLES
4576fca56fbSSascha Wildner.Bd -literal -offset indent
4586fca56fbSSascha Wildner$ file file.c file /dev/{wd0a,hda}
4596fca56fbSSascha Wildnerfile.c:   C program text
4606fca56fbSSascha Wildnerfile:     ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
4616fca56fbSSascha Wildner          dynamically linked (uses shared libs), stripped
4626fca56fbSSascha Wildner/dev/wd0a: block special (0/0)
4636fca56fbSSascha Wildner/dev/hda: block special (3/0)
4646fca56fbSSascha Wildner
4656fca56fbSSascha Wildner$ file -s /dev/wd0{b,d}
4666fca56fbSSascha Wildner/dev/wd0b: data
4676fca56fbSSascha Wildner/dev/wd0d: x86 boot sector
4686fca56fbSSascha Wildner
4696fca56fbSSascha Wildner$ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
4706fca56fbSSascha Wildner/dev/hda:   x86 boot sector
4716fca56fbSSascha Wildner/dev/hda1:  Linux/i386 ext2 filesystem
4726fca56fbSSascha Wildner/dev/hda2:  x86 boot sector
4736fca56fbSSascha Wildner/dev/hda3:  x86 boot sector, extended partition table
4746fca56fbSSascha Wildner/dev/hda4:  Linux/i386 ext2 filesystem
4756fca56fbSSascha Wildner/dev/hda5:  Linux/i386 swap file
4766fca56fbSSascha Wildner/dev/hda6:  Linux/i386 swap file
4776fca56fbSSascha Wildner/dev/hda7:  Linux/i386 swap file
4786fca56fbSSascha Wildner/dev/hda8:  Linux/i386 swap file
4796fca56fbSSascha Wildner/dev/hda9:  empty
4806fca56fbSSascha Wildner/dev/hda10: empty
4816fca56fbSSascha Wildner
4826fca56fbSSascha Wildner$ file -i file.c file /dev/{wd0a,hda}
4836fca56fbSSascha Wildnerfile.c:      text/x-c
4846fca56fbSSascha Wildnerfile:        application/x-executable
4856fca56fbSSascha Wildner/dev/hda:    application/x-not-regular-file
4866fca56fbSSascha Wildner/dev/wd0a:   application/x-not-regular-file
4876fca56fbSSascha Wildner
4886fca56fbSSascha Wildner.Ed
489327e51cbSPeter Avalos.Sh SEE ALSO
49079343712SPeter Avalos.Xr hexdump 1 ,
491a96e001bSPeter Avalos.Xr od 1 ,
492a96e001bSPeter Avalos.Xr strings 1 ,
493c30bd091SSascha Wildner.Xr magic __FSECTION__
494327e51cbSPeter Avalos.Sh STANDARDS CONFORMANCE
495327e51cbSPeter AvalosThis program is believed to exceed the System V Interface Definition
496327e51cbSPeter Avalosof FILE(CMD), as near as one can determine from the vague language
497327e51cbSPeter Avaloscontained therein.
498327e51cbSPeter AvalosIts behavior is mostly compatible with the System V program of the same name.
499327e51cbSPeter AvalosThis version knows more magic, however, so it will produce
500327e51cbSPeter Avalosdifferent (albeit more accurate) output in many cases.
501327e51cbSPeter Avalos.\" URL: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html
502327e51cbSPeter Avalos.Pp
503327e51cbSPeter AvalosThe one significant difference
504327e51cbSPeter Avalosbetween this version and System V
505327e51cbSPeter Avalosis that this version treats any white space
506327e51cbSPeter Avalosas a delimiter, so that spaces in pattern strings must be escaped.
507327e51cbSPeter AvalosFor example,
508327e51cbSPeter Avalos.Bd -literal -offset indent
509a96e001bSPeter Avalos\*[Gt]10	string	language impress\ 	(imPRESS data)
510327e51cbSPeter Avalos.Ed
511327e51cbSPeter Avalos.Pp
512327e51cbSPeter Avalosin an existing magic file would have to be changed to
513327e51cbSPeter Avalos.Bd -literal -offset indent
514a96e001bSPeter Avalos\*[Gt]10	string	language\e impress	(imPRESS data)
515327e51cbSPeter Avalos.Ed
516327e51cbSPeter Avalos.Pp
517327e51cbSPeter AvalosIn addition, in this version, if a pattern string contains a backslash,
518327e51cbSPeter Avalosit must be escaped.
519327e51cbSPeter AvalosFor example
520327e51cbSPeter Avalos.Bd -literal -offset indent
521327e51cbSPeter Avalos0	string		\ebegindata	Andrew Toolkit document
522327e51cbSPeter Avalos.Ed
523327e51cbSPeter Avalos.Pp
524327e51cbSPeter Avalosin an existing magic file would have to be changed to
525327e51cbSPeter Avalos.Bd -literal -offset indent
526327e51cbSPeter Avalos0	string		\e\ebegindata	Andrew Toolkit document
527327e51cbSPeter Avalos.Ed
528327e51cbSPeter Avalos.Pp
529327e51cbSPeter AvalosSunOS releases 3.2 and later from Sun Microsystems include a
530327e51cbSPeter Avalos.Nm
531327e51cbSPeter Avaloscommand derived from the System V one, but with some extensions.
532a96e001bSPeter AvalosThis version differs from Sun's only in minor ways.
533327e51cbSPeter AvalosIt includes the extension of the
534a96e001bSPeter Avalos.Sq \*[Am]
535327e51cbSPeter Avalosoperator, used as,
536327e51cbSPeter Avalosfor example,
537327e51cbSPeter Avalos.Bd -literal -offset indent
538a96e001bSPeter Avalos\*[Gt]16	long\*[Am]0x7fffffff	\*[Gt]0		not stripped
539327e51cbSPeter Avalos.Ed
5406fca56fbSSascha Wildner.Sh SECURITY
5416fca56fbSSascha WildnerOn systems where libseccomp
5426fca56fbSSascha Wildner.Pa ( https://github.com/seccomp/libseccomp )
5436fca56fbSSascha Wildneris available,
5446fca56fbSSascha Wildner.Nm
5456fca56fbSSascha Wildneris enforces limiting system calls to only the ones necessary for the
5466fca56fbSSascha Wildneroperation of the program.
5476fca56fbSSascha WildnerThis enforcement does not provide any security benefit when
5486fca56fbSSascha Wildner.Nm
5496fca56fbSSascha Wildneris asked to decompress input files running external programs with
5506fca56fbSSascha Wildnerthe
5516fca56fbSSascha Wildner.Fl z
5526fca56fbSSascha Wildneroption.
5536fca56fbSSascha WildnerTo enable execution of external decompressors, one needs to disable
5546fca56fbSSascha Wildnersandboxing using the
5556fca56fbSSascha Wildner.Fl S
5566fca56fbSSascha Wildnerflag.
557327e51cbSPeter Avalos.Sh MAGIC DIRECTORY
558327e51cbSPeter AvalosThe magic file entries have been collected from various sources,
559327e51cbSPeter Avalosmainly USENET, and contributed by various authors.
560327e51cbSPeter AvalosChristos Zoulas (address below) will collect additional
561327e51cbSPeter Avalosor corrected magic file entries.
562327e51cbSPeter AvalosA consolidation of magic file entries
563327e51cbSPeter Avaloswill be distributed periodically.
564327e51cbSPeter Avalos.Pp
565327e51cbSPeter AvalosThe order of entries in the magic file is significant.
566327e51cbSPeter AvalosDepending on what system you are using, the order that
567327e51cbSPeter Avalosthey are put together may be incorrect.
568327e51cbSPeter AvalosIf your old
569327e51cbSPeter Avalos.Nm
570327e51cbSPeter Avaloscommand uses a magic file,
571327e51cbSPeter Avaloskeep the old magic file around for comparison purposes
572327e51cbSPeter Avalos(rename it to
573327e51cbSPeter Avalos.Pa __MAGIC__.orig ) .
574327e51cbSPeter Avalos.Sh HISTORY
575327e51cbSPeter AvalosThere has been a
576327e51cbSPeter Avalos.Nm
577327e51cbSPeter Avaloscommand in every
578327e51cbSPeter Avalos.Dv UNIX since at least Research Version 4
579327e51cbSPeter Avalos(man page dated November, 1973).
580327e51cbSPeter AvalosThe System V version introduced one significant major change:
58179343712SPeter Avalosthe external list of magic types.
582327e51cbSPeter AvalosThis slowed the program down slightly but made it a lot more flexible.
583327e51cbSPeter Avalos.Pp
584327e51cbSPeter AvalosThis program, based on the System V version,
585ff91a668SPeter Avaloswas written by Ian Darwin
586ff91a668SPeter Avalos.Aq ian@darwinsys.com
587327e51cbSPeter Avaloswithout looking at anybody else's source code.
588327e51cbSPeter Avalos.Pp
589327e51cbSPeter AvalosJohn Gilmore revised the code extensively, making it better than
590327e51cbSPeter Avalosthe first version.
591327e51cbSPeter AvalosGeoff Collyer found several inadequacies
592327e51cbSPeter Avalosand provided some magic file entries.
593c30bd091SSascha WildnerContributions of the
594a96e001bSPeter Avalos.Sq \*[Am]
595a96e001bSPeter Avalosoperator by Rob McMahon,
596ff91a668SPeter Avalos.Aq cudcv@warwick.ac.uk ,
597ff91a668SPeter Avalos1989.
598327e51cbSPeter Avalos.Pp
599a96e001bSPeter AvalosGuy Harris,
600a96e001bSPeter Avalos.Aq guy@netapp.com ,
601ff91a668SPeter Avalosmade many changes from 1993 to the present.
602327e51cbSPeter Avalos.Pp
603327e51cbSPeter AvalosPrimary development and maintenance from 1990 to the present by
604ff91a668SPeter AvalosChristos Zoulas
605ff91a668SPeter Avalos.Aq christos@astron.com .
606327e51cbSPeter Avalos.Pp
607ff91a668SPeter AvalosAltered by Chris Lowth
608ff91a668SPeter Avalos.Aq chris@lowth.com ,
609ff91a668SPeter Avalos2000: handle the
610327e51cbSPeter Avalos.Fl i
61179343712SPeter Avalosoption to output mime type strings, using an alternative
612327e51cbSPeter Avalosmagic file and internal logic.
613327e51cbSPeter Avalos.Pp
614ff91a668SPeter AvalosAltered by Eric Fischer
615a96e001bSPeter Avalos.Aq enf@pobox.com ,
616a96e001bSPeter AvalosJuly, 2000,
617a96e001bSPeter Avalosto identify character codes and attempt to identify the languages
618327e51cbSPeter Avalosof non-ASCII files.
619327e51cbSPeter Avalos.Pp
620ff91a668SPeter AvalosAltered by Reuben Thomas
621ff91a668SPeter Avalos.Aq rrt@sc3d.org ,
622ff91a668SPeter Avalos2007-2011, to improve MIME support, merge MIME and non-MIME magic,
623ff91a668SPeter Avalossupport directories as well as files of magic, apply many bug fixes,
624ff91a668SPeter Avalosupdate and fix a lot of magic, improve the build system, improve the
625ff91a668SPeter Avalosdocumentation, and rewrite the Python bindings in pure Python.
62679343712SPeter Avalos.Pp
62779343712SPeter AvalosThe list of contributors to the
62879343712SPeter Avalos.Sq magic
62979343712SPeter Avalosdirectory (magic files)
63079343712SPeter Avalosis too long to include here.
631327e51cbSPeter AvalosYou know who you are; thank you.
63279343712SPeter AvalosMany contributors are listed in the source files.
633327e51cbSPeter Avalos.Sh LEGAL NOTICE
634327e51cbSPeter AvalosCopyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999.
635327e51cbSPeter AvalosCovered by the standard Berkeley Software Distribution copyright; see the file
636e4d4ce0cSPeter AvalosCOPYING in the source distribution.
637327e51cbSPeter Avalos.Pp
638327e51cbSPeter AvalosThe files
639a96e001bSPeter Avalos.Pa tar.h
640327e51cbSPeter Avalosand
641a96e001bSPeter Avalos.Pa is_tar.c
642327e51cbSPeter Avaloswere written by John Gilmore from his public-domain
643327e51cbSPeter Avalos.Xr tar 1
644327e51cbSPeter Avalosprogram, and are not covered by the above license.
645327e51cbSPeter Avalos.Sh BUGS
646e4d4ce0cSPeter AvalosPlease report bugs and send patches to the bug tracker at
6476fca56fbSSascha Wildner.Pa https://bugs.astron.com/
648e4d4ce0cSPeter Avalosor the mailing list at
6496fca56fbSSascha Wildner.Aq file@astron.com
650e8af9738SPeter Avalos(visit
6516fca56fbSSascha Wildner.Pa https://mailman.astron.com/mailman/listinfo/file
652e8af9738SPeter Avalosfirst to subscribe).
653ff91a668SPeter Avalos.Sh TODO
654ff91a668SPeter AvalosFix output so that tests for MIME and APPLE flags are not needed all
655e8af9738SPeter Avalosover the place, and actual output is only done in one place.
656e8af9738SPeter AvalosThis needs a design.
657e8af9738SPeter AvalosSuggestion: push possible outputs on to a list, then pick the
658e8af9738SPeter Avaloslast-pushed (most specific, one hopes) value at the end, or
659e8af9738SPeter Avalosuse a default if the list is empty.
660e8af9738SPeter AvalosThis should not slow down evaluation.
661327e51cbSPeter Avalos.Pp
662c30bd091SSascha WildnerThe handling of
663c30bd091SSascha Wildner.Dv MAGIC_CONTINUE
664c30bd091SSascha Wildnerand printing \e012- between entries is clumsy and complicated; refactor
665c30bd091SSascha Wildnerand centralize.
666c30bd091SSascha Wildner.Pp
667c30bd091SSascha WildnerSome of the encoding logic is hard-coded in encoding.c and can be moved
668c30bd091SSascha Wildnerto the magic files if we had a !:charset annotation
669c30bd091SSascha Wildner.Pp
670e8af9738SPeter AvalosContinue to squash all magic bugs.
671e8af9738SPeter AvalosSee Debian BTS for a good source.
672327e51cbSPeter Avalos.Pp
673ff91a668SPeter AvalosStore arbitrarily long strings, for example for %s patterns, so that
674e8af9738SPeter Avalosthey can be printed out.
675e8af9738SPeter AvalosFixes Debian bug #271672.
676c30bd091SSascha WildnerThis can be done by allocating strings in a string pool, storing the
677c30bd091SSascha Wildnerstring pool at the end of the magic file and converting all the string
678c30bd091SSascha Wildnerpointers to relative offsets from the string pool.
679327e51cbSPeter Avalos.Pp
680ff91a668SPeter AvalosAdd syntax for relative offsets after current level (Debian bug #466037).
681327e51cbSPeter Avalos.Pp
682ff91a668SPeter AvalosMake file -ki work, i.e. give multiple MIME types.
683327e51cbSPeter Avalos.Pp
684ff91a668SPeter AvalosAdd a zip library so we can peek inside Office2007 documents to
685c30bd091SSascha Wildnerprint more details about their contents.
686ff91a668SPeter Avalos.Pp
687ff91a668SPeter AvalosAdd an option to print URLs for the sources of the file descriptions.
688e8af9738SPeter Avalos.Pp
689e8af9738SPeter AvalosCombine script searches and add a way to map executable names to MIME
690e8af9738SPeter Avalostypes (e.g. have a magic value for !:mime which causes the resulting
691e8af9738SPeter Avalosstring to be looked up in a table).
692e8af9738SPeter AvalosThis would avoid adding the same magic repeatedly for each new
693e8af9738SPeter Avaloshash-bang interpreter.
694e8af9738SPeter Avalos.Pp
695c30bd091SSascha WildnerWhen a file descriptor is available, we can skip and adjust the buffer
696c30bd091SSascha Wildnerinstead of the hacky buffer management we do now.
697c30bd091SSascha Wildner.Pp
698e8af9738SPeter AvalosFix
699e8af9738SPeter Avalos.Dq name
700e8af9738SPeter Avalosand
701e8af9738SPeter Avalos.Dq use
702e8af9738SPeter Avalosto check for consistency at compile time (duplicate
703e8af9738SPeter Avalos.Dq name ,
704e8af9738SPeter Avalos.Dq use
705e8af9738SPeter Avalospointing to undefined
706e8af9738SPeter Avalos.Dq name
707e8af9738SPeter Avalos).
708e8af9738SPeter AvalosMake
709e8af9738SPeter Avalos.Dq name
710e8af9738SPeter Avalos/
711e8af9738SPeter Avalos.Dq use
712e8af9738SPeter Avalosmore efficient by keeping a sorted list of names.
713e8af9738SPeter AvalosSpecial-case ^ to flip endianness in the parser so that it does not
714e8af9738SPeter Avaloshave to be escaped, and document it.
715c30bd091SSascha Wildner.Pp
716c30bd091SSascha WildnerIf the offsets specified internally in the file exceed the buffer size
717c30bd091SSascha Wildner(
718c30bd091SSascha Wildner.Dv HOWMANY
719c30bd091SSascha Wildnervariable in file.h), then we don't seek to that offset, but we give up.
720c30bd091SSascha WildnerIt would be better if buffer managements was done when the file descriptor
721c30bd091SSascha Wildneris available so move around the file.
722c30bd091SSascha WildnerOne must be careful though because this has performance (and thus security
723c30bd091SSascha Wildnerconsiderations).
724327e51cbSPeter Avalos.Sh AVAILABILITY
725327e51cbSPeter AvalosYou can obtain the original author's latest version by anonymous FTP
726a96e001bSPeter Avaloson
727a96e001bSPeter Avalos.Pa ftp.astron.com
728327e51cbSPeter Avalosin the directory
729a96e001bSPeter Avalos.Pa /pub/file/file-X.YZ.tar.gz .
730