home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / file39a.zip / file.man < prev    next >
Text File  |  1993-08-05  |  15KB  |  397 lines

  1.  
  2.  
  3.  
  4. FILE(1)                                                   FILE(1)
  5.  
  6.  
  7. NNAAMMEE
  8.        _f_i_l_e - determine file type
  9.  
  10. SSYYNNOOPPSSIISS
  11.        ffiillee [ --cc ] [ --zz ] [ --LL ] [ --ff namefile ] [ --mm magicfile ]
  12.        file ...
  13.  
  14. DDEESSCCRRIIPPTTIIOONN
  15.        _F_i_l_e tests each argument in an  attempt  to  classify  it.
  16.        There  are  three  sets of tests, performed in this order:
  17.        filesystem tests, magic number tests, and language  tests.
  18.        The  _f_i_r_s_t  test  that succeeds causes the file type to be
  19.        printed.
  20.  
  21.        The type printed will usually contain  one  of  the  words
  22.        tteexxtt (the file contains only ASCII characters and is prob-
  23.        ably safe to read on an ASCII terminal),  eexxeeccuuttaabbllee  (the
  24.        file  contains the result of compiling a program in a form
  25.        understandable to some UNIX kernel or  another),  or  ddaattaa
  26.        meaning  anything  else  (data is usually `binary' or non-
  27.        printable).  Exceptions are well-known file formats  (core
  28.        files,  tar  archives)  that  are  known to contain binary
  29.        data.  When modifying the file _/_e_t_c_/_m_a_g_i_c or  the  program
  30.        itself,  pprreesseerrvvee tthheessee kkeeyywwoorrddss ..  People depend on know-
  31.        ing that all the readable files in a  directory  have  the
  32.        word  ``text'' printed.  Don't do as Berkeley did - change
  33.        ``shell commands text'' to ``shell script''.
  34.  
  35.        The filesystem tests are based  on  examining  the  return
  36.        from  a _s_t_a_t(2) system call.  The program checks to see if
  37.        the file is empty, or if it's some sort of  special  file.
  38.        Any  known  file  types  appropriate to the system you are
  39.        running  on  (sockets,  symbolic  links,  or  named  pipes
  40.        (FIFOs) on those systems that implement them) are intuited
  41.        if they are defined in the system header file  ssyyss//ssttaatt..hh.
  42.  
  43.        The  magic  number  tests are used to check for files with
  44.        data in particular fixed formats.  The  canonical  example
  45.        of  this  is  a binary executable (compiled program) aa..oouutt
  46.        file, whose format is  defined  in  aa..oouutt..hh  and  possibly
  47.        eexxeecc..hh  in  the  standard  include directory.  These files
  48.        have a `magic number' stored in a  particular  place  near
  49.        the  beginning  of  the file that tells the UNIX operating
  50.        system that the file is a binary executable, and which  of
  51.        several  types thereof.  The concept of `magic number' has
  52.        been applied by extension to data files.   Any  file  with
  53.        some invariant identifier at a small fixed offset into the
  54.        file can usually be described in this way.   The  informa-
  55.        tion   in   these  files  is  read  from  the  magic  file
  56.        _/_e_t_c_/_m_a_g_i_c_.
  57.  
  58.        If an argument appears to be an ASCII file, _f_i_l_e  attempts
  59.        to  guess  its language.  The language tests look for par-
  60.        ticular strings (cf _n_a_m_e_s_._h) that can appear  anywhere  in
  61.  
  62.  
  63.  
  64.                    Copyright but distributable                  1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. FILE(1)                                                   FILE(1)
  71.  
  72.  
  73.        the  first few blocks of a file.  For example, the keyword
  74.        ..bbrr indicates that the file is most likely a  troff  input
  75.        file,  just  as  the keyword ssttrruucctt indicates a C program.
  76.        These tests  are  less  reliable  than  the  previous  two
  77.        groups,  so  they  are  performed last.  The language test
  78.        routines also  test  for  some  miscellany  (such  as  _t_a_r
  79.        archives)  and determine whether an unknown file should be
  80.        labelled as `ascii text' or `data'.
  81.  
  82.        Use --mm _f_i_l_e to specify an alternate file of magic numbers.
  83.  
  84.        The --zz tries to look inside compressed files.
  85.  
  86.        The  --cc  option  causes  a checking printout of the parsed
  87.        form of the magic file.  This is usually used in  conjunc-
  88.        tion  with  --mm to debug a new magic file before installing
  89.        it.
  90.  
  91.        The --ff _n_a_m_e_f_i_l_e option specifies that  the  names  of  the
  92.        files  to  be  examined are to be read (one per line) from
  93.        _n_a_m_e_f_i_l_e before the argument list.  Either _n_a_m_e_f_i_l_e or  at
  94.        least  one  filename argument must be present; to test the
  95.        standard input, use ``-'' as a filename argument.
  96.  
  97.        The --LL option causes symlinks to be followed, as the like-
  98.        named option in _l_s(1).
  99.  
  100. FFIILLEESS
  101.        _/_e_t_c_/_m_a_g_i_c - default list of magic numbers
  102.  
  103. SSEEEE AALLSSOO
  104.        _m_a_g_i_c(4) - description of magic file format.
  105.        _S_t_r_i_n_g_s(1), _o_d(1) - tools for examining non-textfiles.
  106.  
  107. SSTTAANNDDAARRDDSS CCOONNFFOORRMMAANNCCEE
  108.        This  program is believed to exceed the System V Interface
  109.        Definition of FILE(CMD), as near as one can determine from
  110.        the  vague  language  contained therein.  Its behaviour is
  111.        mostly compatible with the System V program  of  the  same
  112.        name.   This version knows more magic, however, so it will
  113.        produce different (albeit more accurate)  output  in  many
  114.        cases.
  115.  
  116.        The  one  significant  difference between this version and
  117.        System V is that this version treats any white space as  a
  118.        delimiter,  so  that  spaces  in  pattern  strings must be
  119.        escaped.  For example,
  120.        >10  string    language impress    (imPRESS data)
  121.        in an existing magic file would have to be changed to
  122.        >10  string    language\ impress   (imPRESS data)
  123.        In addition, in this version, if a pattern string contains
  124.        a backslash, it must be escaped.  For example
  125.        0    string         \begindata     Andrew Toolkit document
  126.        in an existing magic file would have to be changed to
  127.  
  128.  
  129.  
  130.                    Copyright but distributable                  2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. FILE(1)                                                   FILE(1)
  137.  
  138.  
  139.        0    string         \\begindata    Andrew Toolkit document
  140.  
  141.        SunOS releases 3.2 and later from Sun Microsystems include
  142.        a _f_i_l_e(1) command derived from the System V one, but  with
  143.        some  extensions.   My  version differs from Sun's only in
  144.        minor ways.  It includes the extension of the  `&'  opera-
  145.        tor, used as, for example,
  146.        >16  long&0x7fffffff     >0        not stripped
  147.  
  148. MMAAGGIICC DDIIRREECCTTOORRYY
  149.        The  magic  file  entries have been collected from various
  150.        sources,  mainly  USENET,  and  contributed   by   various
  151.        authors.   Ian  Darwin  (address below) will collect addi-
  152.        tional or corrected magic file entries.   A  consolidation
  153.        of magic file entries will be distributed periodically.
  154.  
  155.        The  order  of  entries  in the magic file is significant.
  156.        Depending on what system you are  using,  the  order  that
  157.        they  are put together may be incorrect.  If your old _f_i_l_e
  158.        command uses a magic file, keep the old magic file  around
  159.        for comparison purposes (rename it to _/_e_t_c_/_m_a_g_i_c_._o_r_i_g).
  160.  
  161. HHIISSTTOORRYY
  162.        There has been a _f_i_l_e command in every UNIX since at least
  163.        Research Version 6 (man page dated  January,  1975).   The
  164.        System  V version introduced one significant major change:
  165.        the external list of magic number types.  This slowed  the
  166.        program down slightly but made it a lot more flexible.
  167.  
  168.        This  program,  based on the System V version, was written
  169.        by Ian Darwin without looking  at  anybody  else's  source
  170.        code.
  171.  
  172.        John  Gilmore revised the code extensively, making it bet-
  173.        ter than the first version.  Geoff Collyer  found  several
  174.        inadequacies  and  provided  some magic file entries.  The
  175.        program has undergone continued evolution since.
  176.  
  177. AAUUTTHHOORR
  178.        Written  by  Ian  F.  Darwin,  UUCP   address   {utzoo   |
  179.        ihnp4}!darwin!ian,  Internet  address  ian@sq.com,  postal
  180.        address: P.O. Box 603, Station F, Toronto, Ontario, CANADA
  181.        M4Y 2L8.
  182.  
  183.        Altered  by  Rob  McMahon,  cudcv@warwick.ac.uk,  1989, to
  184.        extend the `&' operator from simple `x&y != 0' to `x&y  op
  185.        z'.
  186.  
  187.        Altered by Guy Harris, guy@auspex.com, 1993, to:
  188.  
  189.               put  the ``old-style'' `&' operator back the way it
  190.               was, because 1) Rob McMahon's change broke the pre-
  191.               vious  style  of  usage, 2) the SunOS ``new-style''
  192.               `&' operator, which this version of _f_i_l_e  supports,
  193.  
  194.  
  195.  
  196.                    Copyright but distributable                  3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. FILE(1)                                                   FILE(1)
  203.  
  204.  
  205.               also handles `x&y op z', and 3) Rob's change wasn't
  206.               documented in any case;
  207.  
  208.               put in multiple levels of `>';
  209.  
  210.               put in ``beshort'', ``leshort'', etc.  keywords  to
  211.               look  at  numbers  in  the  file in a specific byte
  212.               order, rather than in the native byte order of  the
  213.               process running _f_i_l_e.
  214.  
  215.        Changes by Ian Darwin and various authors including Chris-
  216.        tos Zoulas (christos@ee.cornell.edu), 1990-1992.
  217.  
  218. LLEEGGAALL NNOOTTIICCEE
  219.        Copyright (c) Ian F. Darwin, Toronto, Canada, 1986,  1987,
  220.        1988, 1989, 1990, 1991, 1992, 1993.
  221.  
  222.        This  software  is not subject to and may not be made sub-
  223.        ject to any license of the American  Telephone  and  Tele-
  224.        graph  Company,  Sun  Microsystems Inc., Digital Equipment
  225.        Inc., Lotus Development Inc., the Regents of  the  Univer-
  226.        sity  of  California, The X Consortium or MIT, or The Free
  227.        Software Foundation.
  228.  
  229.        This software is not subject to any  export  provision  of
  230.        the  United  States  Department  of  Commerce,  and may be
  231.        exported to any country or planet.
  232.  
  233.        Permission is granted to anyone to use this  software  for
  234.        any  purpose  on  any computer system, and to alter it and
  235.        redistribute it freely, subject to the following  restric-
  236.        tions:
  237.  
  238.        1.  The  author is not responsible for the consequences of
  239.        use of this software, no matter how awful,  even  if  they
  240.        arise from flaws in it.
  241.  
  242.        2. The origin of this software must not be misrepresented,
  243.        either by explicit claim or by omission.  Since few  users
  244.        ever  read  sources, credits must appear in the documenta-
  245.        tion.
  246.  
  247.        3. Altered versions must be plainly marked  as  such,  and
  248.        must not be misrepresented as being the original software.
  249.        Since few users ever read sources, credits must appear  in
  250.        the documentation.
  251.  
  252.        4. This notice may not be removed or altered.
  253.  
  254.        A few support files (_g_e_t_o_p_t, _s_t_r_t_o_k) distributed with this
  255.        package are by Henry Spencer and are subject to  the  same
  256.        terms as above.
  257.  
  258.        A  few  simple  support files (_s_t_r_t_o_l, _s_t_r_c_h_r) distributed
  259.  
  260.  
  261.  
  262.                    Copyright but distributable                  4
  263.  
  264.  
  265.  
  266.  
  267.  
  268. FILE(1)                                                   FILE(1)
  269.  
  270.  
  271.        with this package are in the public domain;  they  are  so
  272.        marked.
  273.  
  274.        The  files _t_a_r_._h and _i_s___t_a_r_._c were written by John Gilmore
  275.        from his public-domain _t_a_r program, and are not covered by
  276.        the above restrictions.
  277.  
  278. BBUUGGSS
  279.        There must be a better way to automate the construction of
  280.        the Magic file from all the glop in Magdir.  What  is  it?
  281.        Better  yet, the magic file should be compiled into binary
  282.        (say, _n_d_b_m(3) or, better yet, fixed-length  ASCII  strings
  283.        for  use  in heterogenous network environments) for faster
  284.        startup.  Then the program would run as fast as  the  Ver-
  285.        sion  7  program of the same name, with the flexibility of
  286.        the System V version.
  287.  
  288.        _F_i_l_e uses several algorithms that favor speed  over  accu-
  289.        racy,  thus  it  can be misled about the contents of ASCII
  290.        files.
  291.  
  292.        The support for ASCII  files  (primarily  for  programming
  293.        languages)  is simplistic, inefficient and requires recom-
  294.        pilation to update.
  295.  
  296.        There should be an ``else'' clause to follow a  series  of
  297.        continuation lines.
  298.  
  299.        The magic file and keywords should have regular expression
  300.        support.  Their use of ASCII TAB as a field  delimiter  is
  301.        ugly  and  makes  it  hard  to  edit  the  files,  but  is
  302.        entrenched.
  303.  
  304.        It might be advisable to allow upper-case letters in  key-
  305.        words  for e.g., troff commands vs man page macros.  Regu-
  306.        lar expression support would make this easy.
  307.  
  308.        The program doesn't grok FORTRAN.  It should  be  able  to
  309.        figure  FORTRAN  by  seeing  some  keywords  which  appear
  310.        indented at the start of line.  Regular expression support
  311.        would make this easy.
  312.  
  313.        The  list  of keywords in _a_s_c_m_a_g_i_c probably belongs in the
  314.        Magic file.  This could be done by using some keyword like
  315.        `*' for the offset value.
  316.  
  317.        Another  optimisation  would  be to sort the magic file so
  318.        that we can just run down all  the  tests  for  the  first
  319.        byte,  first  word,  first long, etc, once we have fetched
  320.        it.  Complain about conflicts in the magic  file  entries.
  321.        Make a rule that the magic entries sort based on file off-
  322.        set rather than position within the magic file?
  323.  
  324.        The program should provide a way to give  an  estimate  of
  325.  
  326.  
  327.  
  328.                    Copyright but distributable                  5
  329.  
  330.  
  331.  
  332.  
  333.  
  334. FILE(1)                                                   FILE(1)
  335.  
  336.  
  337.        ``how good'' a guess is.  We end up removing guesses (e.g.
  338.        ``From '' as first 5 chars of file) because they  are  not
  339.        as  good  as  other  guesses  (e.g. ``Newsgroups:'' versus
  340.        "Return-Path:").  Still, if the others don't pan  out,  it
  341.        should be possible to use the first guess.
  342.  
  343.        This program is slower than some vendors' file commands.
  344.  
  345.        This  manual  page,  and particularly this section, is too
  346.        long.
  347.  
  348. AAVVAAIILLAABBIILLIITTYY
  349.        You can obtain the original  author's  latest  version  by
  350.        anonymous  FTP  on  ffttpp..ccss..ttoorroonnttoo..eedduu  in  the  directory
  351.        //ppuubb//ddaarrwwiinn//ffiillee.
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.                    Copyright but distributable                  6
  395.  
  396.  
  397.