[BACK]Return to file.1 CVS log [TXT][DIR] Up to [local] / src / usr.bin / file

Annotation of src/usr.bin/file/file.1, Revision 1.17

1.17    ! millert     1: .\" $OpenBSD: file.1,v 1.16 2002/01/24 19:34:48 mickey Exp $
1.8       aaron       2: .\" $FreeBSD: src/usr.bin/file/file.1,v 1.16 2000/03/01 12:19:39 sheldonh Exp $
                      3: .Dd July 30, 1997
                      4: .Dt FILE 1
                      5: .Os
                      6: .Sh NAME
                      7: .Nm file
                      8: .Nd determine file type
                      9: .Sh SYNOPSIS
                     10: .Nm file
1.17    ! millert    11: .Op Fl vbczL
1.8       aaron      12: .Op Fl f Ar namefile
                     13: .Op Fl m Ar magicfiles
                     14: .Ar file Op Ar ...
                     15: .Sh DESCRIPTION
1.4       millert    16: This manual page documents version 3.22 of the
1.8       aaron      17: .Nm
1.4       millert    18: command.
1.8       aaron      19: .Nm
1.1       deraadt    20: tests each argument in an attempt to classify it.
                     21: There are three sets of tests, performed in this order:
                     22: filesystem tests, magic number tests, and language tests.
1.8       aaron      23: The first test that succeeds causes the file type to be printed.
                     24: .Pp
1.1       deraadt    25: The type printed will usually contain one of the words
1.8       aaron      26: .Dq text
1.4       millert    27: (the file contains only
1.8       aaron      28: .Tn ASCII
1.4       millert    29: characters and is probably safe to read on an
1.8       aaron      30: .Tn ASCII
1.4       millert    31: terminal),
1.8       aaron      32: .Dq executable
1.1       deraadt    33: (the file contains the result of compiling a program
1.8       aaron      34: in a form understandable to some
                     35: .Ux
                     36: kernel or another),
1.1       deraadt    37: or
1.8       aaron      38: .Dq data
                     39: meaning anything else (data is usually binary or non-printable).
                     40: .Pp
1.1       deraadt    41: Exceptions are well-known file formats (core files, tar archives)
                     42: that are known to contain binary data.
                     43: When modifying the file
1.8       aaron      44: .Pa /etc/magic
1.6       aaron      45: or the program itself,
1.8       aaron      46: .Em "preserve these keywords" .
                     47: .Pp
1.1       deraadt    48: People depend on knowing that all the readable files in a directory
1.8       aaron      49: have the word
                     50: .Dq text
                     51: printed.
                     52: Don't do as Berkeley did; change
                     53: .Dq shell commands text
                     54: to
                     55: .Dq shell script .
                     56: .Pp
1.1       deraadt    57: The filesystem tests are based on examining the return from a
1.8       aaron      58: .Xr stat 2
1.1       deraadt    59: system call.
                     60: The program checks to see if the file is empty,
                     61: or if it's some sort of special file.
                     62: Any known file types appropriate to the system you are running on
                     63: (sockets, symbolic links, or named pipes (FIFOs) on those systems that
                     64: implement them)
                     65: are intuited if they are defined in
                     66: the system header file
1.9       aaron      67: .Aq Pa sys/stat.h .
1.8       aaron      68: .Pp
1.1       deraadt    69: The magic number tests are used to check for files with data in
                     70: particular fixed formats.
                     71: The canonical example of this is a binary executable (compiled program)
1.8       aaron      72: .Pa a.out
1.6       aaron      73: file, whose format is defined in
1.8       aaron      74: .Aq Pa a.out.h
1.1       deraadt    75: and possibly
1.8       aaron      76: .Aq Pa exec.h
1.1       deraadt    77: in the standard include directory.
1.8       aaron      78: These files have a
                     79: .Dq magic number
                     80: stored in a particular place
                     81: near the beginning of the file that tells the
                     82: .Ux
                     83: operating system
1.1       deraadt    84: that the file is a binary executable, and which of several types thereof.
1.8       aaron      85: .Pp
                     86: The concept of magic number has been applied by extension to data files.
1.1       deraadt    87: Any file with some invariant identifier at a small fixed
                     88: offset into the file can usually be described in this way.
                     89: The information in these files is read from the magic file
1.8       aaron      90: .Pa /etc/magic .
                     91: .Pp
1.1       deraadt    92: If an argument appears to be an
1.8       aaron      93: .Tn ASCII
1.1       deraadt    94: file,
1.8       aaron      95: .Nm
1.1       deraadt    96: attempts to guess its language.
1.4       millert    97: The language tests look for particular strings (cf
1.8       aaron      98: .Pa names.h )
1.1       deraadt    99: that can appear anywhere in the first few blocks of a file.
                    100: For example, the keyword
1.8       aaron     101: .Em .br
1.4       millert   102: indicates that the file is most likely a
1.8       aaron     103: .Xr troff 1
1.6       aaron     104: input file, just as the keyword
1.8       aaron     105: .Li struct
1.1       deraadt   106: indicates a C program.
                    107: These tests are less reliable than the previous
                    108: two groups, so they are performed last.
                    109: The language test routines also test for some miscellany
1.6       aaron     110: (such as
1.8       aaron     111: .Xr tar 1
1.1       deraadt   112: archives) and determine whether an unknown file should be
1.8       aaron     113: labelled as
                    114: .Dq ASCII text
                    115: or
                    116: .Dq data .
                    117: .Pp
                    118: The options are as follows:
1.11      aaron     119: .Bl -tag -width Ds
1.8       aaron     120: .It Fl v
1.1       deraadt   121: Print the version of the program and exit.
1.8       aaron     122: .It Fl m Ar list
                    123: Specify an alternate
                    124: .Ar list
                    125: of files containing magic numbers.
1.2       deraadt   126: This can be a single file, or a colon-separated list of files.
1.8       aaron     127: .It Fl z
1.1       deraadt   128: Try to look inside compressed files.
1.17    ! millert   129: .It Fl b
        !           130: Do not prepend filenames to output lines (brief mode).
1.8       aaron     131: .It Fl c
1.1       deraadt   132: Cause a checking printout of the parsed form of the magic file.
1.6       aaron     133: This is usually used in conjunction with
1.8       aaron     134: .Fl m
1.1       deraadt   135: to debug a new magic file before installing it.
1.8       aaron     136: .It Fl f Ar namefile
1.6       aaron     137: Read the names of the files to be examined from
1.8       aaron     138: .Ar namefile
1.6       aaron     139: (one per line)
1.1       deraadt   140: before the argument list.
1.6       aaron     141: Either
1.8       aaron     142: .Ar namefile
1.1       deraadt   143: or at least one filename argument must be present;
1.8       aaron     144: to test the standard input, use
                    145: .Dq -
                    146: as a filename argument.
                    147: .It Fl L
                    148: Cause symlinks to be followed, as the like-named option in
                    149: .Xr ls 1 .
1.1       deraadt   150: (on systems that support symbolic links).
1.8       aaron     151: .El
                    152: .Sh ENVIRONMENT
                    153: .Bl -tag -width indent
1.13      smart     154: .It Ev MAGIC
1.8       aaron     155: Default magic number files.
                    156: .El
1.12      aaron     157: .Sh FILES
                    158: .Bl -tag -width /etc/magic -compact
                    159: .It Pa /etc/magic
                    160: default list of magic numbers
                    161: .El
1.8       aaron     162: .Sh SEE ALSO
                    163: .Xr hexdump 1 ,
                    164: .Xr od 1 ,
                    165: .Xr strings 1 ,
                    166: .Xr magic 5
                    167: .Sh STANDARDS CONFORMANCE
1.1       deraadt   168: This program is believed to exceed the System V Interface Definition
                    169: of FILE(CMD), as near as one can determine from the vague language
1.6       aaron     170: contained therein.
1.1       deraadt   171: Its behaviour is mostly compatible with the System V program of the same name.
                    172: This version knows more magic, however, so it will produce
1.6       aaron     173: different (albeit more accurate) output in many cases.
1.8       aaron     174: .Pp
1.6       aaron     175: The one significant difference
1.1       deraadt   176: between this version and System V
1.8       aaron     177: is that this version treats any white space
1.1       deraadt   178: as a delimiter, so that spaces in pattern strings must be escaped.
                    179: For example,
1.8       aaron     180: .Pp
                    181: >10     string  language impress\       (imPRESS data)
                    182: .Pp
1.1       deraadt   183: in an existing magic file would have to be changed to
1.8       aaron     184: .Pp
                    185: >10     string  language\e impress      (imPRESS data)
                    186: .Pp
1.1       deraadt   187: In addition, in this version, if a pattern string contains a backslash,
1.9       aaron     188: it must be escaped.
                    189: For example
1.8       aaron     190: .Pp
                    191: 0       string          \ebegindata     Andrew Toolkit document
                    192: .Pp
1.1       deraadt   193: in an existing magic file would have to be changed to
1.8       aaron     194: .Pp
                    195: 0       string          \e\ebegindata   Andrew Toolkit document
                    196: .Pp
1.1       deraadt   197: SunOS releases 3.2 and later from Sun Microsystems include a
1.8       aaron     198: .Xr file 1
1.1       deraadt   199: command derived from the System V one, but with some extensions.
                    200: My version differs from Sun's only in minor ways.
1.8       aaron     201: It includes the extension of the
                    202: .Ql &
                    203: operator, used as,
1.1       deraadt   204: for example,
1.8       aaron     205: .Pp
                    206: >16     long&0x7fffffff >0              not stripped
                    207: .Sh MAGIC DIRECTORY
1.1       deraadt   208: The magic file entries have been collected from various sources,
                    209: mainly USENET, and contributed by various authors.
1.8       aaron     210: .An Christos Zoulas
                    211: (address below) will collect additional
1.1       deraadt   212: or corrected magic file entries.
1.6       aaron     213: A consolidation of magic file entries
1.1       deraadt   214: will be distributed periodically.
                    215: The order of entries in the magic file is significant.
                    216: Depending on what system you are using, the order that
                    217: they are put together may be incorrect.
                    218: If your old
1.8       aaron     219: .Nm
1.1       deraadt   220: command uses a magic file,
                    221: keep the old magic file around for comparison purposes
1.6       aaron     222: (rename it to
1.8       aaron     223: .Pa /etc/magic.orig ) .
                    224: .Sh HISTORY
1.6       aaron     225: There has been a
1.8       aaron     226: .Nm
                    227: command in every
                    228: .Ux
1.16      mickey    229: since at least Research Version 4
                    230: (man page dated November, 1973).
1.1       deraadt   231: The System V version introduced one significant major change:
                    232: the external list of magic number types.
                    233: This slowed the program down slightly but made it a lot more flexible.
1.8       aaron     234: .Pp
1.10      ian       235: This program, based on the System V version, was written by
                    236: .An Ian F. Darwin Aq ian@darwinisys.com
1.8       aaron     237: without looking at anybody else's source code.
                    238: .Pp
                    239: .An John Gilmore
                    240: revised the code extensively, making it better than
1.1       deraadt   241: the first version.
1.8       aaron     242: .An Geoff Collyer
                    243: found several inadequacies
1.1       deraadt   244: and provided some magic file entries.
1.8       aaron     245: .Pp
                    246: Altered by
                    247: .An Rob McMahon Aq cudcv@warwick.ac.uk ,
                    248: 1989, to extend the
                    249: .Ql &
                    250: operator from simple
                    251: .Dq x&y != 0
                    252: to
                    253: .Dq x&y op z .
                    254: .Pp
                    255: Altered by
                    256: .An Guy Harris Aq guy@auspex.com ,
                    257: 1993, to:
                    258: .Bl -item -offset indent
                    259: .It
                    260: put the
                    261: .Dq old-style
                    262: .Ql &
                    263: operator back the way it was, because
                    264: .Bl -enum -offset indent
                    265: .It
                    266: Rob McMahon's change broke the
                    267: previous style of usage,
                    268: .It
                    269: The SunOS
                    270: .Dq new-style
                    271: .Ql &
                    272: operator, which this version of
                    273: .Nm
                    274: supports, also handles
                    275: .Dq x&y op z ,
                    276: .It
                    277: Rob's change wasn't documented in any case;
                    278: .El
                    279: .It
                    280: put in multiple levels of
                    281: .Ql > ;
                    282: .It
                    283: put in
                    284: .Dq beshort ,
                    285: .Dq leshort ,
                    286: etc. keywords to look at numbers in the
1.1       deraadt   287: file in a specific byte order, rather than in the native byte order of
                    288: the process running
1.8       aaron     289: .Nm file .
                    290: .El
                    291: .Pp
1.10      ian       292: Currently maintained by
                    293: .An Christos Zoulas Aq christos@zoulas.com .
1.8       aaron     294: .Sh LEGAL NOTICE
1.10      ian       295: Copyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999.
                    296: Covered by the standard Berkeley Software Distribution copyright; see the file
                    297: LEGAL.NOTICE in the distribution.
1.8       aaron     298: .Pp
1.1       deraadt   299: The files
1.8       aaron     300: .Pa tar.h
1.1       deraadt   301: and
1.8       aaron     302: .Pa is_tar.c
                    303: were written by
                    304: .An John Gilmore
                    305: from his public-domain
                    306: .Nm tar
1.10      ian       307: program.
1.8       aaron     308: .Sh BUGS
1.1       deraadt   309: There must be a better way to automate the construction of the Magic
1.8       aaron     310: file from all the glop in Magdir.
                    311: What is it?
1.1       deraadt   312: Better yet, the magic file should be compiled into binary (say,
1.8       aaron     313: .Xr ndbm 3
1.4       millert   314: or, better yet, fixed-length
1.8       aaron     315: .Tn ASCII
1.4       millert   316: strings for use in heterogenous network environments) for faster startup.
1.1       deraadt   317: Then the program would run as fast as the Version 7 program of the same name,
                    318: with the flexibility of the System V version.
1.8       aaron     319: .Pp
                    320: .Nm
1.15      pjanzen   321: uses several algorithms that favor speed over accuracy;
1.4       millert   322: thus it can be misled about the contents of
1.8       aaron     323: .Tn ASCII
1.4       millert   324: files.
1.8       aaron     325: .Pp
1.4       millert   326: The support for
1.8       aaron     327: .Tn ASCII
1.4       millert   328: files (primarily for programming languages)
1.1       deraadt   329: is simplistic, inefficient and requires recompilation to update.
1.8       aaron     330: .Pp
                    331: There should be an
                    332: .Dq else
                    333: clause to follow a series of continuation lines.
                    334: .Pp
1.1       deraadt   335: The magic file and keywords should have regular expression support.
1.4       millert   336: Their use of
1.8       aaron     337: .Tn ASCII TAB
1.4       millert   338: as a field delimiter is ugly and makes
1.1       deraadt   339: it hard to edit the files, but is entrenched.
1.8       aaron     340: .Pp
1.1       deraadt   341: It might be advisable to allow upper-case letters in keywords
1.4       millert   342: for e.g.,
1.8       aaron     343: .Xr troff 1
1.4       millert   344: commands vs man page macros.
1.1       deraadt   345: Regular expression support would make this easy.
1.8       aaron     346: .Pp
1.1       deraadt   347: The program doesn't grok \s-2FORTRAN\s0.
1.6       aaron     348: It should be able to figure \s-2FORTRAN\s0 by seeing some keywords which
1.1       deraadt   349: appear indented at the start of line.
                    350: Regular expression support would make this easy.
1.8       aaron     351: .Pp
1.6       aaron     352: The list of keywords in
1.8       aaron     353: .Em ascmagic
1.1       deraadt   354: probably belongs in the Magic file.
1.8       aaron     355: This could be done by using some keyword like
                    356: .Ql *
                    357: for the offset value.
                    358: .Pp
                    359: Another optimization would be to sort
1.1       deraadt   360: the magic file so that we can just run down all the
                    361: tests for the first byte, first word, first long, etc, once we
1.9       aaron     362: have fetched it.
                    363: Complain about conflicts in the magic file entries.
1.1       deraadt   364: Make a rule that the magic entries sort based on file offset rather
                    365: than position within the magic file?
1.8       aaron     366: .Pp
1.6       aaron     367: The program should provide a way to give an estimate
1.8       aaron     368: of
                    369: .Dq how good
                    370: a guess is.
                    371: We end up removing guesses (e.g.,
                    372: .Dq From\
                    373: as first 5 chars of file) because
                    374: they are not as good as other guesses (e.g.,
                    375: .Dq Newsgroups:
                    376: versus
                    377: .Qq Return-Path: ) .
                    378: Still, if the others don't pan out, it should be
1.6       aaron     379: possible to use the first guess.
1.8       aaron     380: .Pp
                    381: This program is slower than some vendors'
                    382: .Nm
                    383: commands.
                    384: .Pp
1.1       deraadt   385: This manual page, and particularly this section, is too long.
1.8       aaron     386: .Sh AVAILABILITY
1.1       deraadt   387: You can obtain the original author's latest version by anonymous FTP
1.8       aaron     388: on
1.15      pjanzen   389: .Em ftp.astron.com
1.8       aaron     390: in the directory
                    391: .Pa /pub/file/file-X.YY.tar.gz