1*970935fdSSascha Wildner.\" $File: file.man,v 1.144 2021/02/05 22:08:31 christos Exp $ 2*970935fdSSascha Wildner.Dd February 5, 2021 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 13c990e5baSDaniel 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 62*970935fdSSascha Wildner.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 94*970935fdSSascha Wildner.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 101*970935fdSSascha Wildner.Dq magic number 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 171*970935fdSSascha WildnerCauses the 172*970935fdSSascha Wildner.Nm 173*970935fdSSascha Wildnercommand to output the file type and creator code as 1746fca56fbSSascha Wildnerused by older MacOS versions. 1756fca56fbSSascha WildnerThe code consists of eight letters, 176e8af9738SPeter Avalosthe first describing the file type, the latter the creator. 1776fca56fbSSascha WildnerThis option works properly only for file formats that have the 1786fca56fbSSascha Wildnerapple-style output defined. 179a96e001bSPeter Avalos.It Fl b , Fl Fl brief 180327e51cbSPeter AvalosDo not prepend filenames to output lines (brief mode). 181a96e001bSPeter Avalos.It Fl C , Fl Fl compile 182f72f8299SJan LentferWrite a 183f72f8299SJan Lentfer.Pa magic.mgc 184f72f8299SJan Lentferoutput file that contains a pre-parsed version of the magic file or directory. 185a96e001bSPeter Avalos.It Fl c , Fl Fl checking-printout 186327e51cbSPeter AvalosCause a checking printout of the parsed form of the magic file. 187327e51cbSPeter AvalosThis is usually used in conjunction with the 188327e51cbSPeter Avalos.Fl m 189*970935fdSSascha Wildneroption to debug a new magic file before installing it. 190c30bd091SSascha Wildner.It Fl d 191c30bd091SSascha WildnerPrints internal debugging information to stderr. 192e8af9738SPeter Avalos.It Fl E 193e8af9738SPeter AvalosOn filesystem errors (file not found etc), instead of handling the error 194e8af9738SPeter Avalosas regular output as POSIX mandates and keep going, issue an error message 195e8af9738SPeter Avalosand exit. 196a96e001bSPeter Avalos.It Fl e , Fl Fl exclude Ar testname 197327e51cbSPeter AvalosExclude the test named in 198327e51cbSPeter Avalos.Ar testname 199e4d4ce0cSPeter Avalosfrom the list of tests made to determine the file type. 200e4d4ce0cSPeter AvalosValid test names are: 201f72f8299SJan Lentfer.Bl -tag -width compress 202327e51cbSPeter Avalos.It apptype 203327e51cbSPeter Avalos.Dv EMX 204327e51cbSPeter Avalosapplication type (only on EMX). 205e4d4ce0cSPeter Avalos.It ascii 206a96e001bSPeter AvalosVarious types of text files (this test will try to guess the text 207a96e001bSPeter Avalosencoding, irrespective of the setting of the 20879343712SPeter Avalos.Sq encoding 20979343712SPeter Avalosoption). 21079343712SPeter Avalos.It encoding 21179343712SPeter AvalosDifferent text encodings for soft magic tests. 21279343712SPeter Avalos.It tokens 2139f86ab30SPeter AvalosIgnored for backwards compatibility. 21479343712SPeter Avalos.It cdf 21579343712SPeter AvalosPrints details of Compound Document Files. 216327e51cbSPeter Avalos.It compress 21779343712SPeter AvalosChecks for, and looks inside, compressed files. 2186fca56fbSSascha Wildner.It csv 2196fca56fbSSascha WildnerChecks Comma Separated Value files. 220327e51cbSPeter Avalos.It elf 221c30bd091SSascha WildnerPrints ELF file details, provided soft magic tests are enabled and the 222c30bd091SSascha Wildnerelf magic is found. 2236fca56fbSSascha Wildner.It json 2246fca56fbSSascha WildnerExamines JSON (RFC-7159) files by parsing them for compliance. 225327e51cbSPeter Avalos.It soft 22679343712SPeter AvalosConsults magic files. 227327e51cbSPeter Avalos.It tar 2286fca56fbSSascha WildnerExamines tar files by verifying the checksum of the 512 byte tar header. 2296fca56fbSSascha WildnerExcluding this test can provide more detailed content description by using 2306fca56fbSSascha Wildnerthe soft magic method. 231c30bd091SSascha Wildner.It text 232c30bd091SSascha WildnerA synonym for 233c30bd091SSascha Wildner.Sq ascii . 234327e51cbSPeter Avalos.El 235c990e5baSDaniel Fojt.It Fl Fl exclude-quiet 236c990e5baSDaniel FojtLike 237c990e5baSDaniel Fojt.Fl Fl exclude 238c990e5baSDaniel Fojtbut ignore tests that 239c990e5baSDaniel Fojt.Nm 240c990e5baSDaniel Fojtdoes not know about. 241*970935fdSSascha WildnerThis is intended for compatibility with older versions of 242c990e5baSDaniel Fojt.Nm . 243c30bd091SSascha Wildner.It Fl Fl extension 244c30bd091SSascha WildnerPrint a slash-separated list of valid extensions for the file type found. 245a96e001bSPeter Avalos.It Fl F , Fl Fl separator Ar separator 246f72f8299SJan LentferUse the specified string as the separator between the filename and the 247e4d4ce0cSPeter Avalosfile result returned. 248e4d4ce0cSPeter AvalosDefaults to 249f72f8299SJan Lentfer.Sq \&: . 250a96e001bSPeter Avalos.It Fl f , Fl Fl files-from Ar namefile 251327e51cbSPeter AvalosRead the names of the files to be examined from 252327e51cbSPeter Avalos.Ar namefile 253327e51cbSPeter Avalos(one per line) 254327e51cbSPeter Avalosbefore the argument list. 255327e51cbSPeter AvalosEither 256327e51cbSPeter Avalos.Ar namefile 257327e51cbSPeter Avalosor at least one filename argument must be present; 258327e51cbSPeter Avalosto test the standard input, use 259327e51cbSPeter Avalos.Sq - 260327e51cbSPeter Avalosas a filename argument. 2619f86ab30SPeter AvalosPlease note that 2629f86ab30SPeter Avalos.Ar namefile 2639f86ab30SPeter Avalosis unwrapped and the enclosed filenames are processed when this option is 2649f86ab30SPeter Avalosencountered and before any further options processing is done. 2659f86ab30SPeter AvalosThis allows one to process multiple lists of files with different command line 2669f86ab30SPeter Avalosarguments on the same 2679f86ab30SPeter Avalos.Nm 2689f86ab30SPeter Avalosinvocation. 2699f86ab30SPeter AvalosThus if you want to set the delimiter, you need to do it before you specify 2709f86ab30SPeter Avalosthe list of files, like: 2719f86ab30SPeter Avalos.Dq Fl F Ar @ Fl f Ar namefile , 2729f86ab30SPeter Avalosinstead of: 2739f86ab30SPeter Avalos.Dq Fl f Ar namefile Fl F Ar @ . 274a96e001bSPeter Avalos.It Fl h , Fl Fl no-dereference 275*970935fdSSascha WildnerThis option causes symlinks not to be followed 276e4d4ce0cSPeter Avalos(on systems that support symbolic links). 277e4d4ce0cSPeter AvalosThis is the default if the environment variable 278327e51cbSPeter Avalos.Dv POSIXLY_CORRECT 279327e51cbSPeter Avalosis not defined. 280a96e001bSPeter Avalos.It Fl i , Fl Fl mime 281*970935fdSSascha WildnerCauses the 282*970935fdSSascha Wildner.Nm 283*970935fdSSascha Wildnercommand to output mime type strings rather than the more 284e4d4ce0cSPeter Avalostraditional human readable ones. 285e4d4ce0cSPeter AvalosThus it may say 28679343712SPeter Avalos.Sq text/plain; charset=us-ascii 287327e51cbSPeter Avalosrather than 288a96e001bSPeter Avalos.Dq ASCII text . 289a96e001bSPeter Avalos.It Fl Fl mime-type , Fl Fl mime-encoding 290327e51cbSPeter AvalosLike 291327e51cbSPeter Avalos.Fl i , 292327e51cbSPeter Avalosbut print only the specified element(s). 293a96e001bSPeter Avalos.It Fl k , Fl Fl keep-going 294e4d4ce0cSPeter AvalosDon't stop at the first match, keep going. 295e4d4ce0cSPeter AvalosSubsequent matches will be 29679343712SPeter Avaloshave the string 29779343712SPeter Avalos.Sq "\[rs]012\- " 29879343712SPeter Avalosprepended. 29979343712SPeter Avalos(If you want a newline, see the 300a96e001bSPeter Avalos.Fl r 30179343712SPeter Avalosoption.) 302e8af9738SPeter AvalosThe magic pattern with the highest strength (see the 303e8af9738SPeter Avalos.Fl l 304e8af9738SPeter Avalosoption) comes first. 305a96e001bSPeter Avalos.It Fl l , Fl Fl list 306e8af9738SPeter AvalosShows a list of patterns and their strength sorted descending by 3076fca56fbSSascha Wildner.Xr magic __FSECTION__ 308e8af9738SPeter Avalosstrength 309e8af9738SPeter Avaloswhich is used for the matching (see also the 310e8af9738SPeter Avalos.Fl k 311e8af9738SPeter Avalosoption). 312a96e001bSPeter Avalos.It Fl L , Fl Fl dereference 313*970935fdSSascha WildnerThis option causes symlinks to be followed, as the like-named option in 314327e51cbSPeter Avalos.Xr ls 1 315327e51cbSPeter Avalos(on systems that support symbolic links). 316327e51cbSPeter AvalosThis is the default if the environment variable 317a96e001bSPeter Avalos.Ev POSIXLY_CORRECT 318327e51cbSPeter Avalosis defined. 319a96e001bSPeter Avalos.It Fl m , Fl Fl magic-file Ar magicfiles 32079343712SPeter AvalosSpecify an alternate list of files and directories containing magic. 32179343712SPeter AvalosThis can be a single item, or a colon-separated list. 322a96e001bSPeter AvalosIf a compiled magic file is found alongside a file or directory, 323a96e001bSPeter Avalosit will be used instead. 324a96e001bSPeter Avalos.It Fl N , Fl Fl no-pad 325f72f8299SJan LentferDon't pad filenames so that they align in the output. 326a96e001bSPeter Avalos.It Fl n , Fl Fl no-buffer 327327e51cbSPeter AvalosForce stdout to be flushed after checking each file. 328327e51cbSPeter AvalosThis is only useful if checking a list of files. 329327e51cbSPeter AvalosIt is intended to be used by programs that want filetype output from a pipe. 330a96e001bSPeter Avalos.It Fl p , Fl Fl preserve-date 331327e51cbSPeter AvalosOn systems that support 332a96e001bSPeter Avalos.Xr utime 3 333327e51cbSPeter Avalosor 334327e51cbSPeter Avalos.Xr utimes 2 , 335327e51cbSPeter Avalosattempt to preserve the access time of files analyzed, to pretend that 336327e51cbSPeter Avalos.Nm 337327e51cbSPeter Avalosnever read them. 33882c5fa3eSPeter Avalos.It Fl P , Fl Fl parameter Ar name=value 33982c5fa3eSPeter AvalosSet various parameter limits. 340c30bd091SSascha Wildner.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent 34182c5fa3eSPeter Avalos.It Sy "Name" Ta Sy "Default" Ta Sy "Explanation" 342c30bd091SSascha Wildner.It Li bytes Ta 1048576 Ta max number of bytes to read from file 343c990e5baSDaniel Fojt.It Li elf_notes Ta 256 Ta max ELF notes processed 344c990e5baSDaniel Fojt.It Li elf_phnum Ta 2048 Ta max ELF program sections processed 345c990e5baSDaniel Fojt.It Li elf_shnum Ta 32768 Ta max ELF sections processed 346*970935fdSSascha Wildner.It Li encoding Ta 65536 Ta max number of bytes to scan for encoding evaluation 347c990e5baSDaniel Fojt.It Li indir Ta 50 Ta recursion limit for indirect magic 348c990e5baSDaniel Fojt.It Li name Ta 50 Ta use count limit for name/use magic 349c990e5baSDaniel Fojt.It Li regex Ta 8192 Ta length limit for regex searches 35082c5fa3eSPeter Avalos.El 351a96e001bSPeter Avalos.It Fl r , Fl Fl raw 352327e51cbSPeter AvalosDon't translate unprintable characters to \eooo. 353327e51cbSPeter AvalosNormally 354327e51cbSPeter Avalos.Nm 355327e51cbSPeter Avalostranslates unprintable characters to their octal representation. 356a96e001bSPeter Avalos.It Fl s , Fl Fl special-files 357327e51cbSPeter AvalosNormally, 358327e51cbSPeter Avalos.Nm 359327e51cbSPeter Avalosonly attempts to read and determine the type of argument files which 360327e51cbSPeter Avalos.Xr stat 2 361327e51cbSPeter Avalosreports are ordinary files. 362327e51cbSPeter AvalosThis prevents problems, because reading special files may have peculiar 363327e51cbSPeter Avalosconsequences. 364327e51cbSPeter AvalosSpecifying the 365327e51cbSPeter Avalos.Fl s 366327e51cbSPeter Avalosoption causes 367327e51cbSPeter Avalos.Nm 368327e51cbSPeter Avalosto also read argument files which are block or character special files. 369327e51cbSPeter AvalosThis is useful for determining the filesystem types of the data in raw 370327e51cbSPeter Avalosdisk partitions, which are block special files. 371327e51cbSPeter AvalosThis option also causes 372327e51cbSPeter Avalos.Nm 373327e51cbSPeter Avalosto disregard the file size as reported by 374327e51cbSPeter Avalos.Xr stat 2 375327e51cbSPeter Avalossince on some systems it reports a zero size for raw disk partitions. 3766fca56fbSSascha Wildner.It Fl S , Fl Fl no-sandbox 3776fca56fbSSascha WildnerOn systems where libseccomp 3786fca56fbSSascha Wildner.Pa ( https://github.com/seccomp/libseccomp ) 3796fca56fbSSascha Wildneris available, the 3806fca56fbSSascha Wildner.Fl S 381*970935fdSSascha Wildneroption disables sandboxing which is enabled by default. 382*970935fdSSascha WildnerThis option is needed for 383*970935fdSSascha Wildner.Nm 384*970935fdSSascha Wildnerto execute external decompressing programs, 3856fca56fbSSascha Wildneri.e. when the 3866fca56fbSSascha Wildner.Fl z 387*970935fdSSascha Wildneroption is specified and the built-in decompressors are not available. 3886fca56fbSSascha WildnerOn systems where sandboxing is not available, this option has no effect. 389a96e001bSPeter Avalos.It Fl v , Fl Fl version 390327e51cbSPeter AvalosPrint the version of the program and exit. 391a96e001bSPeter Avalos.It Fl z , Fl Fl uncompress 392327e51cbSPeter AvalosTry to look inside compressed files. 393c30bd091SSascha Wildner.It Fl Z , Fl Fl uncompress-noreport 394c30bd091SSascha WildnerTry to look inside compressed files, but report information about the contents 395c30bd091SSascha Wildneronly not the compression. 396a96e001bSPeter Avalos.It Fl 0 , Fl Fl print0 397327e51cbSPeter AvalosOutput a null character 398327e51cbSPeter Avalos.Sq \e0 399e4d4ce0cSPeter Avalosafter the end of the filename. 400e4d4ce0cSPeter AvalosNice to 401327e51cbSPeter Avalos.Xr cut 1 402e4d4ce0cSPeter Avalosthe output. 403e8af9738SPeter AvalosThis does not affect the separator, which is still printed. 404c30bd091SSascha Wildner.Pp 405c30bd091SSascha WildnerIf this option is repeated more than once, then 406c30bd091SSascha Wildner.Nm 407c30bd091SSascha Wildnerprints just the filename followed by a NUL followed by the description 408c30bd091SSascha Wildner(or ERROR: text) followed by a second NUL for each entry. 409327e51cbSPeter Avalos.It Fl -help 410327e51cbSPeter AvalosPrint a help message and exit. 411327e51cbSPeter Avalos.El 412327e51cbSPeter Avalos.Sh ENVIRONMENT 413327e51cbSPeter AvalosThe environment variable 414a96e001bSPeter Avalos.Ev MAGIC 41579343712SPeter Avaloscan be used to set the default magic file name. 416327e51cbSPeter AvalosIf that variable is set, then 417327e51cbSPeter Avalos.Nm 418327e51cbSPeter Avaloswill not attempt to open 419327e51cbSPeter Avalos.Pa $HOME/.magic . 420327e51cbSPeter Avalos.Nm 421327e51cbSPeter Avalosadds 422a96e001bSPeter Avalos.Dq Pa .mgc 423327e51cbSPeter Avalosto the value of this variable as appropriate. 424327e51cbSPeter AvalosThe environment variable 425a96e001bSPeter Avalos.Ev POSIXLY_CORRECT 42679343712SPeter Avaloscontrols (on systems that support symbolic links), whether 427327e51cbSPeter Avalos.Nm 428e4d4ce0cSPeter Avaloswill attempt to follow symlinks or not. 429e4d4ce0cSPeter AvalosIf set, then 430327e51cbSPeter Avalos.Nm 431e4d4ce0cSPeter Avalosfollows symlink, otherwise it does not. 432e4d4ce0cSPeter AvalosThis is also controlled by the 433327e51cbSPeter Avalos.Fl L 434327e51cbSPeter Avalosand 435327e51cbSPeter Avalos.Fl h 436327e51cbSPeter Avalosoptions. 4376fca56fbSSascha Wildner.Sh FILES 4386fca56fbSSascha Wildner.Bl -tag -width __MAGIC__.mgc -compact 4396fca56fbSSascha Wildner.It Pa __MAGIC__.mgc 4406fca56fbSSascha WildnerDefault compiled list of magic. 4416fca56fbSSascha Wildner.It Pa __MAGIC__ 4426fca56fbSSascha WildnerDirectory containing default magic files. 4436fca56fbSSascha Wildner.El 4446fca56fbSSascha Wildner.Sh EXIT STATUS 4456fca56fbSSascha Wildner.Nm 4466fca56fbSSascha Wildnerwill exit with 4476fca56fbSSascha Wildner.Dv 0 4486fca56fbSSascha Wildnerif the operation was successful or 4496fca56fbSSascha Wildner.Dv >0 4506fca56fbSSascha Wildnerif an error was encountered. 4516fca56fbSSascha WildnerThe following errors cause diagnostic messages, but don't affect the program 4526fca56fbSSascha Wildnerexit code (as POSIX requires), unless 4536fca56fbSSascha Wildner.Fl E 4546fca56fbSSascha Wildneris specified: 4556fca56fbSSascha Wildner.Bl -bullet -compact -offset indent 4566fca56fbSSascha Wildner.It 4576fca56fbSSascha WildnerA file cannot be found 4586fca56fbSSascha Wildner.It 4596fca56fbSSascha WildnerThere is no permission to read a file 4606fca56fbSSascha Wildner.It 4616fca56fbSSascha WildnerThe file type cannot be determined 4626fca56fbSSascha Wildner.El 4636fca56fbSSascha Wildner.Sh EXAMPLES 4646fca56fbSSascha Wildner.Bd -literal -offset indent 4656fca56fbSSascha Wildner$ file file.c file /dev/{wd0a,hda} 4666fca56fbSSascha Wildnerfile.c: C program text 4676fca56fbSSascha Wildnerfile: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), 4686fca56fbSSascha Wildner dynamically linked (uses shared libs), stripped 4696fca56fbSSascha Wildner/dev/wd0a: block special (0/0) 4706fca56fbSSascha Wildner/dev/hda: block special (3/0) 4716fca56fbSSascha Wildner 4726fca56fbSSascha Wildner$ file -s /dev/wd0{b,d} 4736fca56fbSSascha Wildner/dev/wd0b: data 4746fca56fbSSascha Wildner/dev/wd0d: x86 boot sector 4756fca56fbSSascha Wildner 4766fca56fbSSascha Wildner$ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10} 4776fca56fbSSascha Wildner/dev/hda: x86 boot sector 4786fca56fbSSascha Wildner/dev/hda1: Linux/i386 ext2 filesystem 4796fca56fbSSascha Wildner/dev/hda2: x86 boot sector 4806fca56fbSSascha Wildner/dev/hda3: x86 boot sector, extended partition table 4816fca56fbSSascha Wildner/dev/hda4: Linux/i386 ext2 filesystem 4826fca56fbSSascha Wildner/dev/hda5: Linux/i386 swap file 4836fca56fbSSascha Wildner/dev/hda6: Linux/i386 swap file 4846fca56fbSSascha Wildner/dev/hda7: Linux/i386 swap file 4856fca56fbSSascha Wildner/dev/hda8: Linux/i386 swap file 4866fca56fbSSascha Wildner/dev/hda9: empty 4876fca56fbSSascha Wildner/dev/hda10: empty 4886fca56fbSSascha Wildner 4896fca56fbSSascha Wildner$ file -i file.c file /dev/{wd0a,hda} 4906fca56fbSSascha Wildnerfile.c: text/x-c 4916fca56fbSSascha Wildnerfile: application/x-executable 4926fca56fbSSascha Wildner/dev/hda: application/x-not-regular-file 4936fca56fbSSascha Wildner/dev/wd0a: application/x-not-regular-file 4946fca56fbSSascha Wildner 4956fca56fbSSascha Wildner.Ed 496327e51cbSPeter Avalos.Sh SEE ALSO 49779343712SPeter Avalos.Xr hexdump 1 , 498a96e001bSPeter Avalos.Xr od 1 , 499a96e001bSPeter Avalos.Xr strings 1 , 500c30bd091SSascha Wildner.Xr magic __FSECTION__ 501327e51cbSPeter Avalos.Sh STANDARDS CONFORMANCE 502327e51cbSPeter AvalosThis program is believed to exceed the System V Interface Definition 503327e51cbSPeter Avalosof FILE(CMD), as near as one can determine from the vague language 504327e51cbSPeter Avaloscontained therein. 505327e51cbSPeter AvalosIts behavior is mostly compatible with the System V program of the same name. 506327e51cbSPeter AvalosThis version knows more magic, however, so it will produce 507327e51cbSPeter Avalosdifferent (albeit more accurate) output in many cases. 508327e51cbSPeter Avalos.\" URL: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html 509327e51cbSPeter Avalos.Pp 510327e51cbSPeter AvalosThe one significant difference 511327e51cbSPeter Avalosbetween this version and System V 512327e51cbSPeter Avalosis that this version treats any white space 513327e51cbSPeter Avalosas a delimiter, so that spaces in pattern strings must be escaped. 514327e51cbSPeter AvalosFor example, 515327e51cbSPeter Avalos.Bd -literal -offset indent 516a96e001bSPeter Avalos\*[Gt]10 string language impress\ (imPRESS data) 517327e51cbSPeter Avalos.Ed 518327e51cbSPeter Avalos.Pp 519327e51cbSPeter Avalosin an existing magic file would have to be changed to 520327e51cbSPeter Avalos.Bd -literal -offset indent 521a96e001bSPeter Avalos\*[Gt]10 string language\e impress (imPRESS data) 522327e51cbSPeter Avalos.Ed 523327e51cbSPeter Avalos.Pp 524327e51cbSPeter AvalosIn addition, in this version, if a pattern string contains a backslash, 525327e51cbSPeter Avalosit must be escaped. 526327e51cbSPeter AvalosFor example 527327e51cbSPeter Avalos.Bd -literal -offset indent 528327e51cbSPeter Avalos0 string \ebegindata Andrew Toolkit document 529327e51cbSPeter Avalos.Ed 530327e51cbSPeter Avalos.Pp 531327e51cbSPeter Avalosin an existing magic file would have to be changed to 532327e51cbSPeter Avalos.Bd -literal -offset indent 533327e51cbSPeter Avalos0 string \e\ebegindata Andrew Toolkit document 534327e51cbSPeter Avalos.Ed 535327e51cbSPeter Avalos.Pp 536327e51cbSPeter AvalosSunOS releases 3.2 and later from Sun Microsystems include a 537327e51cbSPeter Avalos.Nm 538327e51cbSPeter Avaloscommand derived from the System V one, but with some extensions. 539a96e001bSPeter AvalosThis version differs from Sun's only in minor ways. 540327e51cbSPeter AvalosIt includes the extension of the 541a96e001bSPeter Avalos.Sq \*[Am] 542327e51cbSPeter Avalosoperator, used as, 543327e51cbSPeter Avalosfor example, 544327e51cbSPeter Avalos.Bd -literal -offset indent 545a96e001bSPeter Avalos\*[Gt]16 long\*[Am]0x7fffffff \*[Gt]0 not stripped 546327e51cbSPeter Avalos.Ed 5476fca56fbSSascha Wildner.Sh SECURITY 5486fca56fbSSascha WildnerOn systems where libseccomp 5496fca56fbSSascha Wildner.Pa ( https://github.com/seccomp/libseccomp ) 5506fca56fbSSascha Wildneris available, 5516fca56fbSSascha Wildner.Nm 5526fca56fbSSascha Wildneris enforces limiting system calls to only the ones necessary for the 5536fca56fbSSascha Wildneroperation of the program. 5546fca56fbSSascha WildnerThis enforcement does not provide any security benefit when 5556fca56fbSSascha Wildner.Nm 5566fca56fbSSascha Wildneris asked to decompress input files running external programs with 5576fca56fbSSascha Wildnerthe 5586fca56fbSSascha Wildner.Fl z 5596fca56fbSSascha Wildneroption. 5606fca56fbSSascha WildnerTo enable execution of external decompressors, one needs to disable 5616fca56fbSSascha Wildnersandboxing using the 5626fca56fbSSascha Wildner.Fl S 563*970935fdSSascha Wildneroption. 564327e51cbSPeter Avalos.Sh MAGIC DIRECTORY 565327e51cbSPeter AvalosThe magic file entries have been collected from various sources, 566327e51cbSPeter Avalosmainly USENET, and contributed by various authors. 567327e51cbSPeter AvalosChristos Zoulas (address below) will collect additional 568327e51cbSPeter Avalosor corrected magic file entries. 569327e51cbSPeter AvalosA consolidation of magic file entries 570327e51cbSPeter Avaloswill be distributed periodically. 571327e51cbSPeter Avalos.Pp 572327e51cbSPeter AvalosThe order of entries in the magic file is significant. 573327e51cbSPeter AvalosDepending on what system you are using, the order that 574327e51cbSPeter Avalosthey are put together may be incorrect. 575327e51cbSPeter AvalosIf your old 576327e51cbSPeter Avalos.Nm 577327e51cbSPeter Avaloscommand uses a magic file, 578327e51cbSPeter Avaloskeep the old magic file around for comparison purposes 579327e51cbSPeter Avalos(rename it to 580327e51cbSPeter Avalos.Pa __MAGIC__.orig ) . 581327e51cbSPeter Avalos.Sh HISTORY 582327e51cbSPeter AvalosThere has been a 583327e51cbSPeter Avalos.Nm 584327e51cbSPeter Avaloscommand in every 585327e51cbSPeter Avalos.Dv UNIX since at least Research Version 4 586327e51cbSPeter Avalos(man page dated November, 1973). 587327e51cbSPeter AvalosThe System V version introduced one significant major change: 58879343712SPeter Avalosthe external list of magic types. 589327e51cbSPeter AvalosThis slowed the program down slightly but made it a lot more flexible. 590327e51cbSPeter Avalos.Pp 591327e51cbSPeter AvalosThis program, based on the System V version, 592ff91a668SPeter Avaloswas written by Ian Darwin 593ff91a668SPeter Avalos.Aq ian@darwinsys.com 594327e51cbSPeter Avaloswithout looking at anybody else's source code. 595327e51cbSPeter Avalos.Pp 596327e51cbSPeter AvalosJohn Gilmore revised the code extensively, making it better than 597327e51cbSPeter Avalosthe first version. 598327e51cbSPeter AvalosGeoff Collyer found several inadequacies 599327e51cbSPeter Avalosand provided some magic file entries. 600c30bd091SSascha WildnerContributions of the 601a96e001bSPeter Avalos.Sq \*[Am] 602a96e001bSPeter Avalosoperator by Rob McMahon, 603ff91a668SPeter Avalos.Aq cudcv@warwick.ac.uk , 604ff91a668SPeter Avalos1989. 605327e51cbSPeter Avalos.Pp 606a96e001bSPeter AvalosGuy Harris, 607a96e001bSPeter Avalos.Aq guy@netapp.com , 608ff91a668SPeter Avalosmade many changes from 1993 to the present. 609327e51cbSPeter Avalos.Pp 610327e51cbSPeter AvalosPrimary development and maintenance from 1990 to the present by 611ff91a668SPeter AvalosChristos Zoulas 612ff91a668SPeter Avalos.Aq christos@astron.com . 613327e51cbSPeter Avalos.Pp 614ff91a668SPeter AvalosAltered by Chris Lowth 615ff91a668SPeter Avalos.Aq chris@lowth.com , 616ff91a668SPeter Avalos2000: handle the 617327e51cbSPeter Avalos.Fl i 61879343712SPeter Avalosoption to output mime type strings, using an alternative 619327e51cbSPeter Avalosmagic file and internal logic. 620327e51cbSPeter Avalos.Pp 621ff91a668SPeter AvalosAltered by Eric Fischer 622a96e001bSPeter Avalos.Aq enf@pobox.com , 623a96e001bSPeter AvalosJuly, 2000, 624a96e001bSPeter Avalosto identify character codes and attempt to identify the languages 625327e51cbSPeter Avalosof non-ASCII files. 626327e51cbSPeter Avalos.Pp 627ff91a668SPeter AvalosAltered by Reuben Thomas 628ff91a668SPeter Avalos.Aq rrt@sc3d.org , 629ff91a668SPeter Avalos2007-2011, to improve MIME support, merge MIME and non-MIME magic, 630ff91a668SPeter Avalossupport directories as well as files of magic, apply many bug fixes, 631ff91a668SPeter Avalosupdate and fix a lot of magic, improve the build system, improve the 632ff91a668SPeter Avalosdocumentation, and rewrite the Python bindings in pure Python. 63379343712SPeter Avalos.Pp 63479343712SPeter AvalosThe list of contributors to the 63579343712SPeter Avalos.Sq magic 63679343712SPeter Avalosdirectory (magic files) 63779343712SPeter Avalosis too long to include here. 638327e51cbSPeter AvalosYou know who you are; thank you. 63979343712SPeter AvalosMany contributors are listed in the source files. 640327e51cbSPeter Avalos.Sh LEGAL NOTICE 641327e51cbSPeter AvalosCopyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999. 642327e51cbSPeter AvalosCovered by the standard Berkeley Software Distribution copyright; see the file 643e4d4ce0cSPeter AvalosCOPYING in the source distribution. 644327e51cbSPeter Avalos.Pp 645327e51cbSPeter AvalosThe files 646a96e001bSPeter Avalos.Pa tar.h 647327e51cbSPeter Avalosand 648a96e001bSPeter Avalos.Pa is_tar.c 649327e51cbSPeter Avaloswere written by John Gilmore from his public-domain 650327e51cbSPeter Avalos.Xr tar 1 651327e51cbSPeter Avalosprogram, and are not covered by the above license. 652327e51cbSPeter Avalos.Sh BUGS 653e4d4ce0cSPeter AvalosPlease report bugs and send patches to the bug tracker at 6546fca56fbSSascha Wildner.Pa https://bugs.astron.com/ 655e4d4ce0cSPeter Avalosor the mailing list at 6566fca56fbSSascha Wildner.Aq file@astron.com 657e8af9738SPeter Avalos(visit 6586fca56fbSSascha Wildner.Pa https://mailman.astron.com/mailman/listinfo/file 659e8af9738SPeter Avalosfirst to subscribe). 660ff91a668SPeter Avalos.Sh TODO 661ff91a668SPeter AvalosFix output so that tests for MIME and APPLE flags are not needed all 662e8af9738SPeter Avalosover the place, and actual output is only done in one place. 663e8af9738SPeter AvalosThis needs a design. 664e8af9738SPeter AvalosSuggestion: push possible outputs on to a list, then pick the 665e8af9738SPeter Avaloslast-pushed (most specific, one hopes) value at the end, or 666e8af9738SPeter Avalosuse a default if the list is empty. 667e8af9738SPeter AvalosThis should not slow down evaluation. 668327e51cbSPeter Avalos.Pp 669c30bd091SSascha WildnerThe handling of 670c30bd091SSascha Wildner.Dv MAGIC_CONTINUE 671c30bd091SSascha Wildnerand printing \e012- between entries is clumsy and complicated; refactor 672c30bd091SSascha Wildnerand centralize. 673c30bd091SSascha Wildner.Pp 674c30bd091SSascha WildnerSome of the encoding logic is hard-coded in encoding.c and can be moved 675*970935fdSSascha Wildnerto the magic files if we had a !:charset annotation. 676c30bd091SSascha Wildner.Pp 677e8af9738SPeter AvalosContinue to squash all magic bugs. 678e8af9738SPeter AvalosSee Debian BTS for a good source. 679327e51cbSPeter Avalos.Pp 680ff91a668SPeter AvalosStore arbitrarily long strings, for example for %s patterns, so that 681e8af9738SPeter Avalosthey can be printed out. 682e8af9738SPeter AvalosFixes Debian bug #271672. 683c30bd091SSascha WildnerThis can be done by allocating strings in a string pool, storing the 684c30bd091SSascha Wildnerstring pool at the end of the magic file and converting all the string 685c30bd091SSascha Wildnerpointers to relative offsets from the string pool. 686327e51cbSPeter Avalos.Pp 687ff91a668SPeter AvalosAdd syntax for relative offsets after current level (Debian bug #466037). 688327e51cbSPeter Avalos.Pp 689ff91a668SPeter AvalosMake file -ki work, i.e. give multiple MIME types. 690327e51cbSPeter Avalos.Pp 691ff91a668SPeter AvalosAdd a zip library so we can peek inside Office2007 documents to 692c30bd091SSascha Wildnerprint more details about their contents. 693ff91a668SPeter Avalos.Pp 694ff91a668SPeter AvalosAdd an option to print URLs for the sources of the file descriptions. 695e8af9738SPeter Avalos.Pp 696e8af9738SPeter AvalosCombine script searches and add a way to map executable names to MIME 697e8af9738SPeter Avalostypes (e.g. have a magic value for !:mime which causes the resulting 698e8af9738SPeter Avalosstring to be looked up in a table). 699e8af9738SPeter AvalosThis would avoid adding the same magic repeatedly for each new 700e8af9738SPeter Avaloshash-bang interpreter. 701e8af9738SPeter Avalos.Pp 702c30bd091SSascha WildnerWhen a file descriptor is available, we can skip and adjust the buffer 703c30bd091SSascha Wildnerinstead of the hacky buffer management we do now. 704c30bd091SSascha Wildner.Pp 705e8af9738SPeter AvalosFix 706e8af9738SPeter Avalos.Dq name 707e8af9738SPeter Avalosand 708e8af9738SPeter Avalos.Dq use 709e8af9738SPeter Avalosto check for consistency at compile time (duplicate 710e8af9738SPeter Avalos.Dq name , 711e8af9738SPeter Avalos.Dq use 712e8af9738SPeter Avalospointing to undefined 713e8af9738SPeter Avalos.Dq name 714e8af9738SPeter Avalos). 715e8af9738SPeter AvalosMake 716e8af9738SPeter Avalos.Dq name 717e8af9738SPeter Avalos/ 718e8af9738SPeter Avalos.Dq use 719e8af9738SPeter Avalosmore efficient by keeping a sorted list of names. 720e8af9738SPeter AvalosSpecial-case ^ to flip endianness in the parser so that it does not 721e8af9738SPeter Avaloshave to be escaped, and document it. 722c30bd091SSascha Wildner.Pp 723c30bd091SSascha WildnerIf the offsets specified internally in the file exceed the buffer size 724c30bd091SSascha Wildner( 725c30bd091SSascha Wildner.Dv HOWMANY 726c30bd091SSascha Wildnervariable in file.h), then we don't seek to that offset, but we give up. 727c30bd091SSascha WildnerIt would be better if buffer managements was done when the file descriptor 728*970935fdSSascha Wildneris available so we can seek around the file. 729*970935fdSSascha WildnerOne must be careful though because this has performance and thus security 730*970935fdSSascha Wildnerconsiderations, because one can slow down things by repeateadly seeking. 731*970935fdSSascha Wildner.Pp 732*970935fdSSascha WildnerThere is support now for keeping separate buffers and having offsets from 733*970935fdSSascha Wildnerthe end of the file, but the internal buffer management still needs an 734*970935fdSSascha Wildneroverhaul. 735327e51cbSPeter Avalos.Sh AVAILABILITY 736327e51cbSPeter AvalosYou can obtain the original author's latest version by anonymous FTP 737a96e001bSPeter Avaloson 738a96e001bSPeter Avalos.Pa ftp.astron.com 739327e51cbSPeter Avalosin the directory 740a96e001bSPeter Avalos.Pa /pub/file/file-X.YZ.tar.gz . 741