?? file.man
字號:
.\" $File: file.man,v 1.65 2007/01/25 21:05:46 christos Exp $.Dd January 8, 2007.Dt FILE __CSECTION__.Os.Sh NAME.Nm file.Nd determine file type.Sh SYNOPSIS.Nm.Op Fl bchikLnNprsvz.Op Fl f Ar namefile.Op Fl F Ar separator.Op Fl m Ar magicfiles.Ar file.Nm.Fl C.Op Fl m Ar magicfile.Sh DESCRIPTIONThis manual page documents version __VERSION__ of the.Nmcommand..Pp.Nmtests each argument in an attempt to classify it.There are three sets of tests, performed in this order:filesystem tests, magic number tests, and language tests.The.Em firsttest that succeeds causes the file type to be printed..PpThe type printed will usually contain one of the words.Em text(the file contains onlyprinting characters and a few common controlcharacters and is probably safe to read on an.Dv ASCIIterminal),.Em executable(the file contains the result of compiling a programin a form understandable to some .Dv UNIXkernel or another),or.Em datameaning anything else (data is usually .Sq binaryor non-printable).Exceptions are well-known file formats (core files, tar archives)that are known to contain binary data.When modifying the file.Pa __MAGIC__or the program itself, make sure to.Em "preserve these keywords" .People depend on knowing that all the readable files in a directoryhave the word .Dq textprinted.Don't do as Berkeley did and change .Dq shell commands textto .Dq shell script .Note that the file.Pa __MAGIC__is built mechanically from a large number of small files inthe subdirectory.Pa Magdirin the source distribution of this program..PpThe filesystem tests are based on examining the return from a.Xr stat 2system call.The program checks to see if the file is empty,or if it's some sort of special file.Any known file types appropriate to the system you are running on(sockets, symbolic links, or named pipes (FIFOs) on those systems thatimplement them)are intuited if they are defined inthe system header file.In sys/stat.h ..PpThe magic number tests are used to check for files with data inparticular fixed formats.The canonical example of this is a binary executable (compiled program).Dv a.outfile, whose format is defined in .In elf.h ,.In a.out.hand possibly.In exec.hin the standard include directory.These files have a .Sq "magic number"stored in a particular placenear the beginning of the file that tells the .Dv UNIX operating systemthat the file is a binary executable, and which of several types thereof.The concept of a.Sq "magic number"has been applied by extension to data files.Any file with some invariant identifier at a small fixedoffset into the file can usually be described in this way.The information identifying these files is read from the compiledmagic file.Pa __MAGIC__.mgc ,or .Pa __MAGIC__if the compile file does not exist. In addition.Nmwill look in.Pa $HOME/.magic.mgc ,or.Pa $HOME/.magicfor magic entries..PpIf a file does not match any of the entries in the magic file,it is examined to see if it seems to be a text file.ASCII, ISO-8859-x, non-ISO 8-bit extended-ASCII character sets(such as those used on Macintosh and IBM PC systems),UTF-8-encoded Unicode, UTF-16-encoded Unicode, and EBCDICcharacter sets can be distinguished by the differentranges and sequences of bytes that constitute printable textin each set.If a file passes any of these tests, its character set is reported.ASCII, ISO-8859-x, UTF-8, and extended-ASCII files are identifiedas .Dq textbecause they will be mostly readable on nearly any terminal;UTF-16 and EBCDIC are only .Dq character databecause, whilethey contain text, it is text that will require translationbefore it can be read.In addition,.Nmwill attempt to determine other characteristics of text-type files.If the lines of a file are terminated by CR, CRLF, or NEL, insteadof the Unix-standard LF, this will be reported.Files that contain embedded escape sequences or overstrikingwill also be identified..PpOnce.Nmhas determined the character set used in a text-type file,it willattempt to determine in what language the file is written.The language tests look for particular strings (cf.In names.hthat can appear anywhere in the first few blocks of a file.For example, the keyword.Em .brindicates that the file is most likely a.Xr troff 1input file, just as the keyword .Em structindicates a C program.These tests are less reliable than the previoustwo groups, so they are performed last.The language test routines also test for some miscellany(such as .Xr tar 1archives)..PpAny file that cannot be identified as having been writtenin any of the character sets listed above is simply said to be ``data''..Sh OPTIONS.Bl -tag -width indent.It Fl b , -briefDo not prepend filenames to output lines (brief mode)..It Fl c , -checking-printoutCause a checking printout of the parsed form of the magic file.This is usually used in conjunction with the.Fl mflag to debug a new magic file before installing it..It Fl C , -compileWrite a.Pa magic.mgcoutput file that contains a pre-parsed version of the magic file..It Fl e , -exclude Ar testnameExclude the test named in.Ar testnamefrom the list of tests made to determine the file type. Valid test namesare:.Bl -tag -width.It apptypeCheck for.Dv EMXapplication type (only on EMX)..It asciiCheck for various types of ascii files..It compressDon't look for, or inside compressed files..It elfDon't print elf details..It fortranDon't look for fortran sequences inside ascii files..It softDon't consult magic files..It tarDon't examine tar files..It tokenDon't look for known tokens inside ascii files..It troffDon't look for troff sequences inside ascii files..El.It Fl f , -files-from Ar namefileRead the names of the files to be examined from .Ar namefile(one per line) before the argument list.Either .Ar namefileor at least one filename argument must be present;to test the standard input, use .Sq -as a filename argument..It Fl F , -separator Ar separatorUse the specified string as the separator between the filename and thefile result returned. Defaults to .Sq \&: ..It Fl h , -no-dereferenceoption causes symlinks not to be followed(on systems that support symbolic links). This is the default if theenvironment variable.Dv POSIXLY_CORRECTis not defined..It Fl i , -mimeCauses the file command to output mime type strings rather than the moretraditional human readable ones. Thus it may say.Dq text/plain; charset=us-asciiratherthan.Dq ASCII text .In order for this option to work, file changes the wayit handles files recognized by the command itself (such as many of thetext file types, directories etc), and makes use of an alternative.Dq magicfile.(See.Dq FILESsection, below)..It Fl k , -keep-goingDon't stop at the first match, keep going..It Fl L , -dereferenceoption causes symlinks to be followed, as the like-named option in.Xr ls 1(on systems that support symbolic links).This is the default if the environment variable.Dv POSIXLY_CORRECTis defined..It Fl m , -magic-file Ar listSpecify an alternate list of files containing magic numbers.This can be a single file, or a colon-separated list of files.If a compiled magic file is found alongside, it will be used instead.With the .Fl i or .Fl "mime"option, the program adds.Dq .mimeto each file name..It Fl n , -no-bufferForce stdout to be flushed after checking each file.This is only useful if checking a list of files.It is intended to be used by programs that want filetype output from a pipe..It Fl N , -no-padDon't pad filenames so that they align in the output..It Fl p , -preserve-dateOn systems that support.Xr utime 2or.Xr utimes 2 ,attempt to preserve the access time of files analyzed, to pretend that.Nmnever read them..It Fl r , -rawDon't translate unprintable characters to \eooo.Normally.Nmtranslates unprintable characters to their octal representation..It Fl s , -special-filesNormally,.Nmonly attempts to read and determine the type of argument files which.Xr stat 2reports are ordinary files.This prevents problems, because reading special files may have peculiarconsequences.Specifying the.Fl soption causes.Nmto also read argument files which are block or character special files.This is useful for determining the filesystem types of the data in rawdisk partitions, which are block special files.This option also causes.Nmto disregard the file size as reported by.Xr stat 2since on some systems it reports a zero size for raw disk partitions.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -