1*ddb17682Schristos.\" $NetBSD: file.1,v 1.28 2023/08/18 19:00:10 christos Exp $ 21b108b8bSchristos.\" 3*ddb17682Schristos.\" $File: file.man,v 1.150 2023/05/21 17:08:34 christos Exp $ 4*ddb17682Schristos.Dd May 21, 2023 51b108b8bSchristos.Dt FILE 1 61b108b8bSchristos.Os 71b108b8bSchristos.Sh NAME 81b108b8bSchristos.Nm file 91b108b8bSchristos.Nd determine file type 101b108b8bSchristos.Sh SYNOPSIS 111b108b8bSchristos.Nm 122344ff98Schristos.Bk -words 135efe63deSchristos.Op Fl bcdEhiklLNnprsSvzZ0 142344ff98Schristos.Op Fl Fl apple 1529faeba7Schristos.Op Fl Fl exclude-quiet 1674db5203Schristos.Op Fl Fl extension 172344ff98Schristos.Op Fl Fl mime-encoding 182344ff98Schristos.Op Fl Fl mime-type 192344ff98Schristos.Op Fl e Ar testname 201b108b8bSchristos.Op Fl F Ar separator 2181ee850dSwiz.Op Fl f Ar namefile 221b108b8bSchristos.Op Fl m Ar magicfiles 23fa9ee498Schristos.Op Fl P Ar name=value 242344ff98Schristos.Ar 252344ff98Schristos.Ek 261b108b8bSchristos.Nm 271b108b8bSchristos.Fl C 282344ff98Schristos.Op Fl m Ar magicfiles 291b108b8bSchristos.Nm 3081ee850dSwiz.Op Fl Fl help 311b108b8bSchristos.Sh DESCRIPTION 32*ddb17682SchristosThis manual page documents version 5.45 of the 331b108b8bSchristos.Nm 341b108b8bSchristoscommand. 351b108b8bSchristos.Pp 361b108b8bSchristos.Nm 371b108b8bSchristostests each argument in an attempt to classify it. 381b108b8bSchristosThere are three sets of tests, performed in this order: 391b108b8bSchristosfilesystem tests, magic tests, and language tests. 401b108b8bSchristosThe 411b108b8bSchristos.Em first 421b108b8bSchristostest that succeeds causes the file type to be printed. 431b108b8bSchristos.Pp 441b108b8bSchristosThe type printed will usually contain one of the words 451b108b8bSchristos.Em text 461b108b8bSchristos(the file contains only 471b108b8bSchristosprinting characters and a few common control 481b108b8bSchristoscharacters and is probably safe to read on an 491b108b8bSchristos.Dv ASCII 501b108b8bSchristosterminal), 511b108b8bSchristos.Em executable 521b108b8bSchristos(the file contains the result of compiling a program 531b108b8bSchristosin a form understandable to some 5481ee850dSwiz.Tn UNIX 551b108b8bSchristoskernel or another), 561b108b8bSchristosor 571b108b8bSchristos.Em data 581b108b8bSchristosmeaning anything else (data is usually 5981ee850dSwiz.Dq binary 601b108b8bSchristosor non-printable). 611b108b8bSchristosExceptions are well-known file formats (core files, tar archives) 621b108b8bSchristosthat are known to contain binary data. 631b108b8bSchristosWhen modifying magic files or the program itself, make sure to 64d87b0039Schristos.Em preserve these keywords . 651b108b8bSchristosUsers depend on knowing that all the readable files in a directory 661b108b8bSchristoshave the word 6781ee850dSwiz.Dq text 681b108b8bSchristosprinted. 691b108b8bSchristosDon't do as Berkeley did and change 7081ee850dSwiz.Dq shell commands text 711b108b8bSchristosto 7281ee850dSwiz.Dq shell script . 731b108b8bSchristos.Pp 741b108b8bSchristosThe filesystem tests are based on examining the return from a 751b108b8bSchristos.Xr stat 2 761b108b8bSchristossystem call. 771b108b8bSchristosThe program checks to see if the file is empty, 781b108b8bSchristosor if it's some sort of special file. 791b108b8bSchristosAny known file types appropriate to the system you are running on 801b108b8bSchristos(sockets, symbolic links, or named pipes (FIFOs) on those systems that 811b108b8bSchristosimplement them) 8281ee850dSwizare intuited if they are defined in the system header file 831b108b8bSchristos.In sys/stat.h . 841b108b8bSchristos.Pp 851b108b8bSchristosThe magic tests are used to check for files with data in 861b108b8bSchristosparticular fixed formats. 871b108b8bSchristosThe canonical example of this is a binary executable (compiled program) 881b108b8bSchristos.Dv a.out 891b108b8bSchristosfile, whose format is defined in 901b108b8bSchristos.In elf.h , 911b108b8bSchristos.In a.out.h 921b108b8bSchristosand possibly 931b108b8bSchristos.In exec.h 941b108b8bSchristosin the standard include directory. 951b108b8bSchristosThese files have a 96d87b0039Schristos.Dq magic number 971b108b8bSchristosstored in a particular place 981b108b8bSchristosnear the beginning of the file that tells the 9981ee850dSwiz.Tn UNIX 10081ee850dSwizoperating system 1011b108b8bSchristosthat the file is a binary executable, and which of several types thereof. 1021b108b8bSchristosThe concept of a 103d87b0039Schristos.Dq magic number 1041b108b8bSchristoshas been applied by extension to data files. 1051b108b8bSchristosAny file with some invariant identifier at a small fixed 1061b108b8bSchristosoffset into the file can usually be described in this way. 1071b108b8bSchristosThe information identifying these files is read from the compiled 1081b108b8bSchristosmagic file 1091b108b8bSchristos.Pa /usr/share/misc/magic.mgc , 1101b108b8bSchristosor the files in the directory 1111b108b8bSchristos.Pa /usr/share/misc/magic 11281ee850dSwizif the compiled file does not exist. 11381ee850dSwizIn addition, if 1141b108b8bSchristos.Pa $HOME/.magic.mgc 1151b108b8bSchristosor 1161b108b8bSchristos.Pa $HOME/.magic 1171b108b8bSchristosexists, it will be used in preference to the system magic files. 1181b108b8bSchristos.Pp 1191b108b8bSchristosIf a file does not match any of the entries in the magic file, 1201b108b8bSchristosit is examined to see if it seems to be a text file. 1211b108b8bSchristosASCII, ISO-8859-x, non-ISO 8-bit extended-ASCII character sets 1221b108b8bSchristos(such as those used on Macintosh and IBM PC systems), 1231b108b8bSchristosUTF-8-encoded Unicode, UTF-16-encoded Unicode, and EBCDIC 1241b108b8bSchristoscharacter sets can be distinguished by the different 1251b108b8bSchristosranges and sequences of bytes that constitute printable text 1261b108b8bSchristosin each set. 1271b108b8bSchristosIf a file passes any of these tests, its character set is reported. 1281b108b8bSchristosASCII, ISO-8859-x, UTF-8, and extended-ASCII files are identified 1291b108b8bSchristosas 13081ee850dSwiz.Dq text 1311b108b8bSchristosbecause they will be mostly readable on nearly any terminal; 1321b108b8bSchristosUTF-16 and EBCDIC are only 13381ee850dSwiz.Dq character data 1341b108b8bSchristosbecause, while 1351b108b8bSchristosthey contain text, it is text that will require translation 1361b108b8bSchristosbefore it can be read. 1371b108b8bSchristosIn addition, 1381b108b8bSchristos.Nm 1391b108b8bSchristoswill attempt to determine other characteristics of text-type files. 1401b108b8bSchristosIf the lines of a file are terminated by CR, CRLF, or NEL, instead 1411b108b8bSchristosof the Unix-standard LF, this will be reported. 1421b108b8bSchristosFiles that contain embedded escape sequences or overstriking 1431b108b8bSchristoswill also be identified. 1441b108b8bSchristos.Pp 1451b108b8bSchristosOnce 1461b108b8bSchristos.Nm 1471b108b8bSchristoshas determined the character set used in a text-type file, 1481b108b8bSchristosit will 1491b108b8bSchristosattempt to determine in what language the file is written. 1501b108b8bSchristosThe language tests look for particular strings (cf. 15181ee850dSwiz.In names.h ) 15281ee850dSwizthat can appear anywhere in the first few blocks of a file. 1531b108b8bSchristosFor example, the keyword 1541b108b8bSchristos.Em .br 1551b108b8bSchristosindicates that the file is most likely a 1561b108b8bSchristos.Xr troff 1 1571b108b8bSchristosinput file, just as the keyword 1581b108b8bSchristos.Em struct 1591b108b8bSchristosindicates a C program. 1601b108b8bSchristosThese tests are less reliable than the previous 1611b108b8bSchristostwo groups, so they are performed last. 1621b108b8bSchristosThe language test routines also test for some miscellany 1631b108b8bSchristos(such as 1641b108b8bSchristos.Xr tar 1 165c02f7f97Schristosarchives, JSON files). 1661b108b8bSchristos.Pp 1671b108b8bSchristosAny file that cannot be identified as having been written 1681b108b8bSchristosin any of the character sets listed above is simply said to be 16981ee850dSwiz.Dq data . 1701b108b8bSchristos.Sh OPTIONS 1711b108b8bSchristos.Bl -tag -width indent 172819e6405Schristos.It Fl Fl apple 173d87b0039SchristosCauses the 174d87b0039Schristos.Nm 175d87b0039Schristoscommand to output the file type and creator code as 1765efe63deSchristosused by older MacOS versions. 1775efe63deSchristosThe code consists of eight letters, 178819e6405Schristosthe first describing the file type, the latter the creator. 179d0c65b7bSchristosThis option works properly only for file formats that have the 180d0c65b7bSchristosapple-style output defined. 18181ee850dSwiz.It Fl b , Fl Fl brief 1821b108b8bSchristosDo not prepend filenames to output lines (brief mode). 1832344ff98Schristos.It Fl C , Fl Fl compile 1842344ff98SchristosWrite a 1852344ff98Schristos.Pa magic.mgc 1862344ff98Schristosoutput file that contains a pre-parsed version of the magic file or directory. 18781ee850dSwiz.It Fl c , Fl Fl checking-printout 1881b108b8bSchristosCause a checking printout of the parsed form of the magic file. 1891b108b8bSchristosThis is usually used in conjunction with the 1901b108b8bSchristos.Fl m 191d87b0039Schristosoption to debug a new magic file before installing it. 19274db5203Schristos.It Fl d 19374db5203SchristosPrints internal debugging information to stderr. 194819e6405Schristos.It Fl E 195819e6405SchristosOn filesystem errors (file not found etc), instead of handling the error 196819e6405Schristosas regular output as POSIX mandates and keep going, issue an error message 197819e6405Schristosand exit. 19881ee850dSwiz.It Fl e , Fl Fl exclude Ar testname 1991b108b8bSchristosExclude the test named in 2001b108b8bSchristos.Ar testname 20181ee850dSwizfrom the list of tests made to determine the file type. 20281ee850dSwizValid test names are: 2039132e9e0Schristos.Bl -tag -width compress 2041b108b8bSchristos.It apptype 2051b108b8bSchristos.Dv EMX 2061b108b8bSchristosapplication type (only on EMX). 2072344ff98Schristos.It ascii 20881ee850dSwizVarious types of text files (this test will try to guess the text 20981ee850dSwizencoding, irrespective of the setting of the 2102344ff98Schristos.Sq encoding 2111b108b8bSchristosoption). 2121b108b8bSchristos.It encoding 2131b108b8bSchristosDifferent text encodings for soft magic tests. 2141b108b8bSchristos.It tokens 215046a38ddSchristosIgnored for backwards compatibility. 2161b108b8bSchristos.It cdf 2171b108b8bSchristosPrints details of Compound Document Files. 2181b108b8bSchristos.It compress 2191b108b8bSchristosChecks for, and looks inside, compressed files. 22078a23c3aSchristos.It csv 22178a23c3aSchristosChecks Comma Separated Value files. 2221b108b8bSchristos.It elf 22374db5203SchristosPrints ELF file details, provided soft magic tests are enabled and the 22474db5203Schristoself magic is found. 225c02f7f97Schristos.It json 226c02f7f97SchristosExamines JSON (RFC-7159) files by parsing them for compliance. 2271b108b8bSchristos.It soft 2281b108b8bSchristosConsults magic files. 229*ddb17682Schristos.It simh 230*ddb17682SchristosExamines SIMH tape files. 2311b108b8bSchristos.It tar 2325efe63deSchristosExamines tar files by verifying the checksum of the 512 byte tar header. 2335efe63deSchristosExcluding this test can provide more detailed content description by using 2345efe63deSchristosthe soft magic method. 23574db5203Schristos.It text 23674db5203SchristosA synonym for 23774db5203Schristos.Sq ascii . 2381b108b8bSchristos.El 23929faeba7Schristos.It Fl Fl exclude-quiet 24029faeba7SchristosLike 24129faeba7Schristos.Fl Fl exclude 24229faeba7Schristosbut ignore tests that 24329faeba7Schristos.Nm 24429faeba7Schristosdoes not know about. 245d87b0039SchristosThis is intended for compatibility with older versions of 24629faeba7Schristos.Nm . 24774db5203Schristos.It Fl Fl extension 24874db5203SchristosPrint a slash-separated list of valid extensions for the file type found. 24981ee850dSwiz.It Fl F , Fl Fl separator Ar separator 25081ee850dSwizUse the specified string as the separator between the filename and the 25181ee850dSwizfile result returned. 25281ee850dSwizDefaults to 25381ee850dSwiz.Sq \&: . 25481ee850dSwiz.It Fl f , Fl Fl files-from Ar namefile 2551b108b8bSchristosRead the names of the files to be examined from 2561b108b8bSchristos.Ar namefile 2571b108b8bSchristos(one per line) 2581b108b8bSchristosbefore the argument list. 2591b108b8bSchristosEither 2601b108b8bSchristos.Ar namefile 2611b108b8bSchristosor at least one filename argument must be present; 2621b108b8bSchristosto test the standard input, use 2631b108b8bSchristos.Sq - 2641b108b8bSchristosas a filename argument. 265046a38ddSchristosPlease note that 266046a38ddSchristos.Ar namefile 267046a38ddSchristosis unwrapped and the enclosed filenames are processed when this option is 268046a38ddSchristosencountered and before any further options processing is done. 269046a38ddSchristosThis allows one to process multiple lists of files with different command line 270046a38ddSchristosarguments on the same 271046a38ddSchristos.Nm 272046a38ddSchristosinvocation. 273046a38ddSchristosThus if you want to set the delimiter, you need to do it before you specify 274046a38ddSchristosthe list of files, like: 275046a38ddSchristos.Dq Fl F Ar @ Fl f Ar namefile , 276046a38ddSchristosinstead of: 277046a38ddSchristos.Dq Fl f Ar namefile Fl F Ar @ . 27881ee850dSwiz.It Fl h , Fl Fl no-dereference 279d87b0039SchristosThis option causes symlinks not to be followed 28081ee850dSwiz(on systems that support symbolic links). 28181ee850dSwizThis is the default if the environment variable 2822344ff98Schristos.Dv POSIXLY_CORRECT 2831b108b8bSchristosis not defined. 28481ee850dSwiz.It Fl i , Fl Fl mime 285d87b0039SchristosCauses the 286d87b0039Schristos.Nm 287d87b0039Schristoscommand to output mime type strings rather than the more 28881ee850dSwiztraditional human readable ones. 2892344ff98SchristosThus it may say 2902344ff98Schristos.Sq text/plain; charset=us-ascii 2911b108b8bSchristosrather than 29281ee850dSwiz.Dq ASCII text . 29381ee850dSwiz.It Fl Fl mime-type , Fl Fl mime-encoding 2941b108b8bSchristosLike 2951b108b8bSchristos.Fl i , 2961b108b8bSchristosbut print only the specified element(s). 29781ee850dSwiz.It Fl k , Fl Fl keep-going 29881ee850dSwizDon't stop at the first match, keep going. 2992344ff98SchristosSubsequent matches will be 3002344ff98Schristoshave the string 3012344ff98Schristos.Sq "\[rs]012\- " 3021b108b8bSchristosprepended. 3031b108b8bSchristos(If you want a newline, see the 30481ee850dSwiz.Fl r 3051b108b8bSchristosoption.) 30620d96732SchristosThe magic pattern with the highest strength (see the 30720d96732Schristos.Fl l 30820d96732Schristosoption) comes first. 3092344ff98Schristos.It Fl l , Fl Fl list 31020d96732SchristosShows a list of patterns and their strength sorted descending by 31178a23c3aSchristos.Xr magic 5 31220d96732Schristosstrength 31320d96732Schristoswhich is used for the matching (see also the 31420d96732Schristos.Fl k 31520d96732Schristosoption). 31681ee850dSwiz.It Fl L , Fl Fl dereference 317d87b0039SchristosThis option causes symlinks to be followed, as the like-named option in 3181b108b8bSchristos.Xr ls 1 3191b108b8bSchristos(on systems that support symbolic links). 3201b108b8bSchristosThis is the default if the environment variable 32181ee850dSwiz.Ev POSIXLY_CORRECT 3221b108b8bSchristosis defined. 3232344ff98Schristos.It Fl m , Fl Fl magic-file Ar magicfiles 3241b108b8bSchristosSpecify an alternate list of files and directories containing magic. 3251b108b8bSchristosThis can be a single item, or a colon-separated list. 32681ee850dSwizIf a compiled magic file is found alongside a file or directory, 32781ee850dSwizit will be used instead. 32881ee850dSwiz.It Fl N , Fl Fl no-pad 32981ee850dSwizDon't pad filenames so that they align in the output. 33081ee850dSwiz.It Fl n , Fl Fl no-buffer 3311b108b8bSchristosForce stdout to be flushed after checking each file. 3321b108b8bSchristosThis is only useful if checking a list of files. 3331b108b8bSchristosIt is intended to be used by programs that want filetype output from a pipe. 33481ee850dSwiz.It Fl p , Fl Fl preserve-date 3351b108b8bSchristosOn systems that support 33681ee850dSwiz.Xr utime 3 3371b108b8bSchristosor 3381b108b8bSchristos.Xr utimes 2 , 3391b108b8bSchristosattempt to preserve the access time of files analyzed, to pretend that 3401b108b8bSchristos.Nm 3411b108b8bSchristosnever read them. 342fa9ee498Schristos.It Fl P , Fl Fl parameter Ar name=value 343fa9ee498SchristosSet various parameter limits. 344*ddb17682Schristos.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 345fa9ee498Schristos.It Sy "Name" Ta Sy "Default" Ta Sy "Explanation" 346*ddb17682Schristos.It Li bytes Ta 1M Ta max number of bytes to read from file 34729faeba7Schristos.It Li elf_notes Ta 256 Ta max ELF notes processed 348*ddb17682Schristos.It Li elf_phnum Ta 2K Ta max ELF program sections processed 349*ddb17682Schristos.It Li elf_shnum Ta 32K Ta max ELF sections processed 350*ddb17682Schristos.It Li elf_shsize Ta 128MB Ta max ELF section size processed 351*ddb17682Schristos.It Li encoding Ta 65K Ta max number of bytes to determine encoding 35229faeba7Schristos.It Li indir Ta 50 Ta recursion limit for indirect magic 35329faeba7Schristos.It Li name Ta 50 Ta use count limit for name/use magic 354*ddb17682Schristos.It Li regex Ta 8K Ta length limit for regex searches 355fa9ee498Schristos.El 35681ee850dSwiz.It Fl r , Fl Fl raw 3571b108b8bSchristosDon't translate unprintable characters to \eooo. 3581b108b8bSchristosNormally 3591b108b8bSchristos.Nm 3601b108b8bSchristostranslates unprintable characters to their octal representation. 36181ee850dSwiz.It Fl s , Fl Fl special-files 3621b108b8bSchristosNormally, 3631b108b8bSchristos.Nm 3641b108b8bSchristosonly attempts to read and determine the type of argument files which 3651b108b8bSchristos.Xr stat 2 3661b108b8bSchristosreports are ordinary files. 3671b108b8bSchristosThis prevents problems, because reading special files may have peculiar 3681b108b8bSchristosconsequences. 3691b108b8bSchristosSpecifying the 3701b108b8bSchristos.Fl s 3711b108b8bSchristosoption causes 3721b108b8bSchristos.Nm 3731b108b8bSchristosto also read argument files which are block or character special files. 3741b108b8bSchristosThis is useful for determining the filesystem types of the data in raw 3751b108b8bSchristosdisk partitions, which are block special files. 3761b108b8bSchristosThis option also causes 3771b108b8bSchristos.Nm 3781b108b8bSchristosto disregard the file size as reported by 3791b108b8bSchristos.Xr stat 2 3801b108b8bSchristossince on some systems it reports a zero size for raw disk partitions. 381c02f7f97Schristos.It Fl S , Fl Fl no-sandbox 3825efe63deSchristosOn systems where libseccomp 3835efe63deSchristos.Pa ( https://github.com/seccomp/libseccomp ) 3845efe63deSchristosis available, the 3855efe63deSchristos.Fl S 386d87b0039Schristosoption disables sandboxing which is enabled by default. 387d87b0039SchristosThis option is needed for 388d87b0039Schristos.Nm 389d87b0039Schristosto execute external decompressing programs, 3905efe63deSchristosi.e. when the 3915efe63deSchristos.Fl z 392d87b0039Schristosoption is specified and the built-in decompressors are not available. 39378a23c3aSchristosOn systems where sandboxing is not available, this option has no effect. 39481ee850dSwiz.It Fl v , Fl Fl version 3951b108b8bSchristosPrint the version of the program and exit. 39681ee850dSwiz.It Fl z , Fl Fl uncompress 3971b108b8bSchristosTry to look inside compressed files. 39874db5203Schristos.It Fl Z , Fl Fl uncompress-noreport 39974db5203SchristosTry to look inside compressed files, but report information about the contents 40074db5203Schristosonly not the compression. 4012344ff98Schristos.It Fl 0 , Fl Fl print0 4022344ff98SchristosOutput a null character 4032344ff98Schristos.Sq \e0 4042344ff98Schristosafter the end of the filename. 4052344ff98SchristosNice to 4062344ff98Schristos.Xr cut 1 4072344ff98Schristosthe output. 4088dd459ccSchristosThis does not affect the separator, which is still printed. 40974db5203Schristos.Pp 41074db5203SchristosIf this option is repeated more than once, then 41174db5203Schristos.Nm 41274db5203Schristosprints just the filename followed by a NUL followed by the description 41374db5203Schristos(or ERROR: text) followed by a second NUL for each entry. 4142344ff98Schristos.It Fl -help 4152344ff98SchristosPrint a help message and exit. 4162344ff98Schristos.El 4171b108b8bSchristos.Sh ENVIRONMENT 4181b108b8bSchristosThe environment variable 41981ee850dSwiz.Ev MAGIC 4201b108b8bSchristoscan be used to set the default magic file name. 4211b108b8bSchristosIf that variable is set, then 4221b108b8bSchristos.Nm 4231b108b8bSchristoswill not attempt to open 4241b108b8bSchristos.Pa $HOME/.magic . 4251b108b8bSchristos.Nm 4261b108b8bSchristosadds 42781ee850dSwiz.Dq Pa .mgc 4281b108b8bSchristosto the value of this variable as appropriate. 4291b108b8bSchristosThe environment variable 43081ee850dSwiz.Ev POSIXLY_CORRECT 4311b108b8bSchristoscontrols (on systems that support symbolic links), whether 4321b108b8bSchristos.Nm 43381ee850dSwizwill attempt to follow symlinks or not. 43481ee850dSwizIf set, then 4351b108b8bSchristos.Nm 43681ee850dSwizfollows symlink, otherwise it does not. 43781ee850dSwizThis is also controlled by the 4381b108b8bSchristos.Fl L 4391b108b8bSchristosand 4401b108b8bSchristos.Fl h 4411b108b8bSchristosoptions. 4425efe63deSchristos.Sh FILES 4435efe63deSchristos.Bl -tag -width /usr/share/misc/magic.mgc -compact 4445efe63deSchristos.It Pa /usr/share/misc/magic.mgc 4455efe63deSchristosDefault compiled list of magic. 4465efe63deSchristos.It Pa /usr/share/misc/magic 4475efe63deSchristosDirectory containing default magic files. 4485efe63deSchristos.El 4495efe63deSchristos.Sh EXIT STATUS 4505efe63deSchristos.Nm 4515efe63deSchristoswill exit with 4525efe63deSchristos.Dv 0 4535efe63deSchristosif the operation was successful or 4545efe63deSchristos.Dv >0 4555efe63deSchristosif an error was encountered. 4565efe63deSchristosThe following errors cause diagnostic messages, but don't affect the program 4575efe63deSchristosexit code (as POSIX requires), unless 4585efe63deSchristos.Fl E 4595efe63deSchristosis specified: 4605efe63deSchristos.Bl -bullet -compact -offset indent 4615efe63deSchristos.It 4625efe63deSchristosA file cannot be found 4635efe63deSchristos.It 4645efe63deSchristosThere is no permission to read a file 4655efe63deSchristos.It 4665efe63deSchristosThe file type cannot be determined 4675efe63deSchristos.El 4685efe63deSchristos.Sh EXAMPLES 4695efe63deSchristos.Bd -literal -offset indent 4705efe63deSchristos$ file file.c file /dev/{wd0a,hda} 4715efe63deSchristosfile.c: C program text 4725efe63deSchristosfile: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), 4735efe63deSchristos dynamically linked (uses shared libs), stripped 4745efe63deSchristos/dev/wd0a: block special (0/0) 4755efe63deSchristos/dev/hda: block special (3/0) 4765efe63deSchristos 4775efe63deSchristos$ file -s /dev/wd0{b,d} 4785efe63deSchristos/dev/wd0b: data 4795efe63deSchristos/dev/wd0d: x86 boot sector 4805efe63deSchristos 4815efe63deSchristos$ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10} 4825efe63deSchristos/dev/hda: x86 boot sector 4835efe63deSchristos/dev/hda1: Linux/i386 ext2 filesystem 4845efe63deSchristos/dev/hda2: x86 boot sector 4855efe63deSchristos/dev/hda3: x86 boot sector, extended partition table 4865efe63deSchristos/dev/hda4: Linux/i386 ext2 filesystem 4875efe63deSchristos/dev/hda5: Linux/i386 swap file 4885efe63deSchristos/dev/hda6: Linux/i386 swap file 4895efe63deSchristos/dev/hda7: Linux/i386 swap file 4905efe63deSchristos/dev/hda8: Linux/i386 swap file 4915efe63deSchristos/dev/hda9: empty 4925efe63deSchristos/dev/hda10: empty 4935efe63deSchristos 4945efe63deSchristos$ file -i file.c file /dev/{wd0a,hda} 4955efe63deSchristosfile.c: text/x-c 4965efe63deSchristosfile: application/x-executable 4975efe63deSchristos/dev/hda: application/x-not-regular-file 4985efe63deSchristos/dev/wd0a: application/x-not-regular-file 4995efe63deSchristos 5005efe63deSchristos.Ed 50181ee850dSwiz.Sh SEE ALSO 50281ee850dSwiz.Xr hexdump 1 , 50381ee850dSwiz.Xr od 1 , 50481ee850dSwiz.Xr strings 1 , 505484007c8Sabhinav.Xr magic 5 5062344ff98Schristos.Sh STANDARDS CONFORMANCE 50781ee850dSwizThis program is believed to exceed the System V Interface Definition 50881ee850dSwizof FILE(CMD), as near as one can determine from the vague language 50981ee850dSwizcontained therein. 51081ee850dSwizIts behavior is mostly compatible with the System V program of the same name. 51181ee850dSwizThis version knows more magic, however, so it will produce 51281ee850dSwizdifferent (albeit more accurate) output in many cases. 51381ee850dSwiz.\" URL: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html 51481ee850dSwiz.Pp 51581ee850dSwizThe one significant difference 51681ee850dSwizbetween this version and System V 51781ee850dSwizis that this version treats any white space 51881ee850dSwizas a delimiter, so that spaces in pattern strings must be escaped. 51981ee850dSwizFor example, 52081ee850dSwiz.Bd -literal -offset indent 52181ee850dSwiz\*[Gt]10 string language impress\ (imPRESS data) 52281ee850dSwiz.Ed 52381ee850dSwiz.Pp 52481ee850dSwizin an existing magic file would have to be changed to 52581ee850dSwiz.Bd -literal -offset indent 52681ee850dSwiz\*[Gt]10 string language\e impress (imPRESS data) 52781ee850dSwiz.Ed 52881ee850dSwiz.Pp 52981ee850dSwizIn addition, in this version, if a pattern string contains a backslash, 53081ee850dSwizit must be escaped. 53181ee850dSwizFor example 53281ee850dSwiz.Bd -literal -offset indent 53381ee850dSwiz0 string \ebegindata Andrew Toolkit document 53481ee850dSwiz.Ed 53581ee850dSwiz.Pp 53681ee850dSwizin an existing magic file would have to be changed to 53781ee850dSwiz.Bd -literal -offset indent 53881ee850dSwiz0 string \e\ebegindata Andrew Toolkit document 53981ee850dSwiz.Ed 54081ee850dSwiz.Pp 54181ee850dSwizSunOS releases 3.2 and later from Sun Microsystems include a 54281ee850dSwiz.Nm 54381ee850dSwizcommand derived from the System V one, but with some extensions. 54481ee850dSwizThis version differs from Sun's only in minor ways. 54581ee850dSwizIt includes the extension of the 54681ee850dSwiz.Sq \*[Am] 54781ee850dSwizoperator, used as, 54881ee850dSwizfor example, 54981ee850dSwiz.Bd -literal -offset indent 55081ee850dSwiz\*[Gt]16 long\*[Am]0x7fffffff \*[Gt]0 not stripped 55181ee850dSwiz.Ed 5525efe63deSchristos.Sh SECURITY 5535efe63deSchristosOn systems where libseccomp 5545efe63deSchristos.Pa ( https://github.com/seccomp/libseccomp ) 5555efe63deSchristosis available, 5565efe63deSchristos.Nm 5575efe63deSchristosis enforces limiting system calls to only the ones necessary for the 5585efe63deSchristosoperation of the program. 5595efe63deSchristosThis enforcement does not provide any security benefit when 5605efe63deSchristos.Nm 5615efe63deSchristosis asked to decompress input files running external programs with 5625efe63deSchristosthe 5635efe63deSchristos.Fl z 5645efe63deSchristosoption. 5655efe63deSchristosTo enable execution of external decompressors, one needs to disable 5665efe63deSchristossandboxing using the 5675efe63deSchristos.Fl S 568d87b0039Schristosoption. 56981ee850dSwiz.Sh MAGIC DIRECTORY 57081ee850dSwizThe magic file entries have been collected from various sources, 57181ee850dSwizmainly USENET, and contributed by various authors. 57281ee850dSwizChristos Zoulas (address below) will collect additional 57381ee850dSwizor corrected magic file entries. 57481ee850dSwizA consolidation of magic file entries 57581ee850dSwizwill be distributed periodically. 57681ee850dSwiz.Pp 57781ee850dSwizThe order of entries in the magic file is significant. 57881ee850dSwizDepending on what system you are using, the order that 57981ee850dSwizthey are put together may be incorrect. 58081ee850dSwizIf your old 58181ee850dSwiz.Nm 58281ee850dSwizcommand uses a magic file, 58381ee850dSwizkeep the old magic file around for comparison purposes 58481ee850dSwiz(rename it to 58581ee850dSwiz.Pa /usr/share/misc/magic.orig ) . 5861b108b8bSchristos.Sh HISTORY 5871b108b8bSchristosThere has been a 5881b108b8bSchristos.Nm 5891b108b8bSchristoscommand in every 5901b108b8bSchristos.Dv UNIX since at least Research Version 4 5911b108b8bSchristos(man page dated November, 1973). 5921b108b8bSchristosThe System V version introduced one significant major change: 5931b108b8bSchristosthe external list of magic types. 5941b108b8bSchristosThis slowed the program down slightly but made it a lot more flexible. 5951b108b8bSchristos.Pp 5961b108b8bSchristosThis program, based on the System V version, 59781ee850dSwizwas written by Ian Darwin 59881ee850dSwiz.Aq ian@darwinsys.com 5991b108b8bSchristoswithout looking at anybody else's source code. 6001b108b8bSchristos.Pp 6011b108b8bSchristosJohn Gilmore revised the code extensively, making it better than 6021b108b8bSchristosthe first version. 6031b108b8bSchristosGeoff Collyer found several inadequacies 6041b108b8bSchristosand provided some magic file entries. 60574db5203SchristosContributions of the 60681ee850dSwiz.Sq \*[Am] 6072344ff98Schristosoperator by Rob McMahon, 6082344ff98Schristos.Aq cudcv@warwick.ac.uk , 6092344ff98Schristos1989. 6101b108b8bSchristos.Pp 6112344ff98SchristosGuy Harris, 6122344ff98Schristos.Aq guy@netapp.com , 6132344ff98Schristosmade many changes from 1993 to the present. 6141b108b8bSchristos.Pp 6151b108b8bSchristosPrimary development and maintenance from 1990 to the present by 61681ee850dSwizChristos Zoulas 61781ee850dSwiz.Aq christos@astron.com . 6181b108b8bSchristos.Pp 6192344ff98SchristosAltered by Chris Lowth 6202344ff98Schristos.Aq chris@lowth.com , 6212344ff98Schristos2000: handle the 6221b108b8bSchristos.Fl i 6231b108b8bSchristosoption to output mime type strings, using an alternative 6241b108b8bSchristosmagic file and internal logic. 6251b108b8bSchristos.Pp 62681ee850dSwizAltered by Eric Fischer 62781ee850dSwiz.Aq enf@pobox.com , 62881ee850dSwizJuly, 2000, 6291b108b8bSchristosto identify character codes and attempt to identify the languages 6301b108b8bSchristosof non-ASCII files. 6311b108b8bSchristos.Pp 63281ee850dSwizAltered by Reuben Thomas 63381ee850dSwiz.Aq rrt@sc3d.org , 6342344ff98Schristos2007-2011, to improve MIME support, merge MIME and non-MIME magic, 6352344ff98Schristossupport directories as well as files of magic, apply many bug fixes, 6362344ff98Schristosupdate and fix a lot of magic, improve the build system, improve the 6372344ff98Schristosdocumentation, and rewrite the Python bindings in pure Python. 6381b108b8bSchristos.Pp 6391b108b8bSchristosThe list of contributors to the 6401b108b8bSchristos.Sq magic 6411b108b8bSchristosdirectory (magic files) 6421b108b8bSchristosis too long to include here. 6431b108b8bSchristosYou know who you are; thank you. 6441b108b8bSchristosMany contributors are listed in the source files. 6451b108b8bSchristos.Sh LEGAL NOTICE 6461b108b8bSchristosCopyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999. 6471b108b8bSchristosCovered by the standard Berkeley Software Distribution copyright; see the file 6482344ff98SchristosCOPYING in the source distribution. 6491b108b8bSchristos.Pp 6501b108b8bSchristosThe files 65181ee850dSwiz.Pa tar.h 6521b108b8bSchristosand 65381ee850dSwiz.Pa is_tar.c 6541b108b8bSchristoswere written by John Gilmore from his public-domain 6551b108b8bSchristos.Xr tar 1 6561b108b8bSchristosprogram, and are not covered by the above license. 6572344ff98Schristos.Sh BUGS 6582344ff98SchristosPlease report bugs and send patches to the bug tracker at 659c02f7f97Schristos.Pa https://bugs.astron.com/ 6602344ff98Schristosor the mailing list at 661c02f7f97Schristos.Aq file@astron.com 662819e6405Schristos(visit 663c02f7f97Schristos.Pa https://mailman.astron.com/mailman/listinfo/file 664819e6405Schristosfirst to subscribe). 6652344ff98Schristos.Sh TODO 6662344ff98SchristosFix output so that tests for MIME and APPLE flags are not needed all 667b0605215Schristosover the place, and actual output is only done in one place. 668b0605215SchristosThis needs a design. 669c2e19894SchristosSuggestion: push possible outputs on to a list, then pick the 670c2e19894Schristoslast-pushed (most specific, one hopes) value at the end, or 671b0605215Schristosuse a default if the list is empty. 672b0605215SchristosThis should not slow down evaluation. 6731b108b8bSchristos.Pp 67474db5203SchristosThe handling of 67574db5203Schristos.Dv MAGIC_CONTINUE 67674db5203Schristosand printing \e012- between entries is clumsy and complicated; refactor 67774db5203Schristosand centralize. 67874db5203Schristos.Pp 67974db5203SchristosSome of the encoding logic is hard-coded in encoding.c and can be moved 680d87b0039Schristosto the magic files if we had a !:charset annotation. 68174db5203Schristos.Pp 682b0605215SchristosContinue to squash all magic bugs. 683b0605215SchristosSee Debian BTS for a good source. 6841b108b8bSchristos.Pp 6852344ff98SchristosStore arbitrarily long strings, for example for %s patterns, so that 686b0605215Schristosthey can be printed out. 687b0605215SchristosFixes Debian bug #271672. 68874db5203SchristosThis can be done by allocating strings in a string pool, storing the 68974db5203Schristosstring pool at the end of the magic file and converting all the string 69074db5203Schristospointers to relative offsets from the string pool. 6911b108b8bSchristos.Pp 6922344ff98SchristosAdd syntax for relative offsets after current level (Debian bug #466037). 6932344ff98Schristos.Pp 6942344ff98SchristosMake file -ki work, i.e. give multiple MIME types. 6952344ff98Schristos.Pp 6962344ff98SchristosAdd a zip library so we can peek inside Office2007 documents to 69774db5203Schristosprint more details about their contents. 6982344ff98Schristos.Pp 6992344ff98SchristosAdd an option to print URLs for the sources of the file descriptions. 70020d96732Schristos.Pp 70120d96732SchristosCombine script searches and add a way to map executable names to MIME 70220d96732Schristostypes (e.g. have a magic value for !:mime which causes the resulting 703b0605215Schristosstring to be looked up in a table). 704c2e19894SchristosThis would avoid adding the same magic repeatedly for each new 705c2e19894Schristoshash-bang interpreter. 70620d96732Schristos.Pp 70774db5203SchristosWhen a file descriptor is available, we can skip and adjust the buffer 70874db5203Schristosinstead of the hacky buffer management we do now. 70974db5203Schristos.Pp 71020d96732SchristosFix 71120d96732Schristos.Dq name 71220d96732Schristosand 71320d96732Schristos.Dq use 71420d96732Schristosto check for consistency at compile time (duplicate 71520d96732Schristos.Dq name , 71620d96732Schristos.Dq use 71720d96732Schristospointing to undefined 71820d96732Schristos.Dq name 71920d96732Schristos). 72020d96732SchristosMake 72120d96732Schristos.Dq name 72220d96732Schristos/ 72320d96732Schristos.Dq use 72420d96732Schristosmore efficient by keeping a sorted list of names. 72520d96732SchristosSpecial-case ^ to flip endianness in the parser so that it does not 72620d96732Schristoshave to be escaped, and document it. 72774db5203Schristos.Pp 72874db5203SchristosIf the offsets specified internally in the file exceed the buffer size 72974db5203Schristos( 73074db5203Schristos.Dv HOWMANY 73174db5203Schristosvariable in file.h), then we don't seek to that offset, but we give up. 73274db5203SchristosIt would be better if buffer managements was done when the file descriptor 733d87b0039Schristosis available so we can seek around the file. 734d87b0039SchristosOne must be careful though because this has performance and thus security 735*ddb17682Schristosconsiderations, because one can slow down things by repeatedly seeking. 736d87b0039Schristos.Pp 737d87b0039SchristosThere is support now for keeping separate buffers and having offsets from 738d87b0039Schristosthe end of the file, but the internal buffer management still needs an 739d87b0039Schristosoverhaul. 7401b108b8bSchristos.Sh AVAILABILITY 7411b108b8bSchristosYou can obtain the original author's latest version by anonymous FTP 7421b108b8bSchristoson 74381ee850dSwiz.Pa ftp.astron.com 7441b108b8bSchristosin the directory 74581ee850dSwiz.Pa /pub/file/file-X.YZ.tar.gz . 746