Seth Woolley's Man Viewer

Manual for file - man 1 file

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

FILE(1)                                                                FILE(1)

       file(1,n) - determine file(1,n) type

       file(1,n) [ -bcikLnNprsvz ] [ -f namefile ] [ -F separator ] [ -m magicfiles
       ] file(1,n) ...
       file(1,n) -C [ -m magicfile ]

       This manual page documents version(1,3,5) 4.10 of the file(1,n) command.

       File tests each argument in(1,8) an attempt to classify it.  There are three
       sets  of tests, performed in(1,8) this order: filesystem tests, magic(4,5) number
       tests, and language tests.  The first test  that  succeeds  causes  the
       file(1,n) type to be printed.

       The  type  printed will usually contain one of the words text (the file(1,n)
       contains only printing characters and a few common  control  characters
       and  is  probably  safe  to read(2,n,1 builtins) on an ASCII terminal), executable (the
       file(1,n) contains the result of compiling a program in(1,8) a  form  understand-
       able  to  some  UNIX  kernel or another), or data meaning anything else
       (data is usually `binary' or non-printable).  Exceptions are well-known
       file(1,n)  formats  (core  files,  tar  archives)  that are known to contain
       binary data.  When modifying the file(1,n) /usr/share/misc/file(1,n)/magic(4,5) or the
       program  itself,  preserve  these  keywords .  People depend on knowing
       that all the readable files in(1,8)  a  directory  have  the  word  ``text''
       printed.   Don't  do as Berkeley did and change ``shell commands text''
       to ``shell script''.  Note that the file(1,n) /usr/share/misc/file(1,n)/magic(4,5)  is
       built  mechanically from a large number of small files in(1,8) the subdirec-
       tory Magdir in(1,8) the source distribution of this program.

       The filesystem tests are based on examining the return from  a  stat(1,2)(2)
       system  call.   The  program  checks to see if(3,n) the file(1,n) is empty, or if(3,n)
       it's some sort(1,3) of special file.  Any known file(1,n)  types  appropriate  to
       the  system you are running on (sockets, symbolic links, or named(5,8) pipes
       (FIFOs) on those systems that implement them) are intuited if(3,n) they  are
       defined in(1,8) the system header file(1,n) <sys/stat.h>.

       The magic(4,5) number tests are used to check for files with data in(1,8) partic-
       ular fixed formats.  The canonical example of this  is  a  binary  exe-
       cutable  (compiled  program)  a.out  file(1,n),  whose  format is defined in(1,8)
       a.out.h and possibly exec.h in(1,8) the standard include  directory.   These
       files  have  a  `magic(4,5)  number'  stored  in(1,8) a particular place near the
       beginning of the file(1,n) that tells the UNIX  operating  system  that  the
       file(1,n)  is  a binary executable, and which of several types thereof.  The
       concept of `magic(4,5) number' has been applied by extension to data  files.
       Any  file(1,n)  with  some invariant identifier at a small fixed offset into
       the file(1,n) can usually be described in(1,8) this way.  The information identi-
       fying   these   files   is   read(2,n,1 builtins)   from   the   compiled   magic(4,5)  file(1,n)
       /usr/share/misc/file(1,n)/magic.mgc , or /usr/share/misc/file(1,n)/magic(4,5)  if(3,n)  the
       compile file(1,n) does not exist.

       If  a  file(1,n)  does not match any of the entries in(1,8) the magic(4,5) file(1,n), it is
       examined to see if(3,n) it seems to be a text file.  ASCII, ISO-8859-x, non-
       ISO  8-bit  extended-ASCII character sets (such as those used on Macin-
       tosh and IBM PC systems), UTF-8-encoded  Unicode,  UTF-16-encoded  Uni-
       code,  and  EBCDIC character sets can be distinguished by the different
       ranges and sequences of bytes that constitute printable  text  in(1,8)  each
       set.   If  a  file(1,n)  passes  any  of  these  tests, its character set(7,n,1 builtins) is
       reported.  ASCII, ISO-8859-x, UTF-8, and extended-ASCII files are iden-
       tified  as  ``text'' because they will be mostly readable on nearly any
       terminal; UTF-16 and EBCDIC are only ``character data'' because,  while
       they  contain  text, it is text that will require translation before it
       can be read.  In addition, file(1,n) will attempt to determine other charac-
       teristics of text-type files.  If the lines of a file(1,n) are terminated by
       CR, CRLF, or NEL,  instead  of  the  Unix-standard  LF,  this  will  be
       reported.  Files that contain embedded escape sequences or overstriking
       will also be identified.

       Once file(1,n) has determined the character set(7,n,1 builtins) used in(1,8) a text-type file(1,n), it
       will  attempt  to  determine in(1,8) what language the file(1,n) is written.  The
       language tests look(1,8,3 Search::Dict) for particular strings (cf names.h) that can appear
       anywhere  in(1,8)  the first few blocks of a file.  For example, the keyword
       .br indicates that the file(1,n) is most likely a troff(1) input file(1,n),  just
       as  the  keyword  struct  indicates  a C program.  These tests are less(1,3)
       reliable than the previous two groups, so they are performed last.  The
       language  test  routines  also test for some miscellany (such as tar(1)

       Any file(1,n) that cannot be identified as having been written in(1,8) any of the
       character sets listed above is simply said to be ``data''.

       -b, --brief
               Do not prepend filenames to output lines (brief mode).

       -c, --checking-printout
               Cause a checking printout of the parsed form of the magic(4,5) file.
               This is usually used in(1,8) conjunction with  -m  to  debug  a  new
               magic(4,5) file(1,n) before installing it.

       -C, --compile
               Write  a  magic.mgc output file(1,n) that contains a pre-parsed ver-
               sion(1,3,5) of file.

       -f, --files-from namefile
               Read the names of the files to be examined from  namefile  (one
               per  line)  before  the  argument  list.  Either namefile or at
               least one filename argument must be present; to test the  stan-
               dard input, use ``-'' as a filename argument.

       -F, --separator separator
               Use  the specified string(3,n) as the separator between the filename
               and the file(1,n) result returned. Defaults to ``:''.

       -i, --mime
               Causes the file(1,n) command to output mime type strings rather than
               the  more  traditional  human  readable  ones.  Thus it may say
               ``text/plain; charset=us-ascii'' rather  than  ``ASCII  text''.
               In  order for this option to work, file(1,n) changes the way it han-
               dles files recognised by the command itself (such  as  many  of
               the  text  file(1,n)  types,  directories  etc), and makes use of an
               alternative ``magic(4,5)'' file.  (See ``FILES'' section, below).

       -k, --keep-going
               Don't stop at the first match, keep going.

       -L, --dereference
               option causes symlinks to be followed, as the like-named option
               in(1,8) ls(1).  (on systems that support symbolic links).

       -m, --magic-file list
               Specify  an  alternate  list of files containing magic(4,5) numbers.
               This can be a single file(1,n), or a colon-separated list of  files.
               If  a  compiled  magic(4,5) file(1,n) is found alongside, it will be used
               instead.  With the  -i  or  --mime  option,  the  program  adds
               ".mime" to each file(1,n) name.

       -n, --no-buffer
               Force  stdout  to be flushed after checking each file.  This is
               only useful if(3,n) checking a list of files.  It is intended to  be
               used by programs that want filetype output from a pipe.

       -N, --no-pad
               Don't pad filenames so that they align in(1,8) the output.

       -p, --preserve-date
               On  systems that support utime(2) or utimes(2), attempt to pre-
               serve the access(2,5)  time(1,2,n)  of  files  analyzed,  to  pretend  that
               file(1,n)(2) never read(2,n,1 builtins) them.

       -r, --raw
               Don't  translate unprintable characters to \ooo.  Normally file(1,n)
               translates unprintable characters to  their  octal  representa-

       -s, --special-files
               Normally,  file(1,n) only attempts to read(2,n,1 builtins) and determine the type of
               argument files which stat(1,2)(2) reports are ordinary files.   This
               prevents problems, because reading special files may have pecu-
               liar consequences.  Specifying the -s  option  causes  file(1,n)  to
               also  read(2,n,1 builtins)  argument files which are block or character special
               files.  This is useful for determining the filesystem types  of
               the data in(1,8) raw(3x,7,8,3x cbreak) disk partitions, which are block special files.
               This option also causes file(1,n) to  disregard  the  file(1,n)  size  as
               reported  by  stat(1,2)(2)  since  on some systems it reports a zero
               size for raw(3x,7,8,3x cbreak) disk partitions.

       -v, --version
               Print the version(1,3,5) of the program and exit.

       -z, --uncompress
               Try to look(1,8,3 Search::Dict) inside compressed files.

       --help  Print a help message and exit.

              Default compiled list of magic(4,5) numbers

              Default list of magic(4,5) numbers

              Default compiled list of magic(4,5)  numbers,  used  to  output  mime
              types when the -i option is specified.

              Default  list  of  magic(4,5) numbers, used to output mime types when
              the -i option is specified.

              Local additions to magic(4,5) wisdom.

       The environment variable MAGIC can be used to  set(7,n,1 builtins)  the  default  magic(4,5)
       number file(1,n) name.  file(1,n) adds ".mime" and/or ".mgc" to the value of this
       variable as appropriate.

       magic(4,5)(4) - description of magic(4,5) file(1,n) format.
       strings(1), od(1), hexdump(1) - tools for examining non-textfiles.

       This program is believed to exceed the System V Interface Definition of
       FILE(CMD),  as  near  as one can determine from the vague language con-
       tained therein.  Its behaviour is mostly compatible with the  System  V
       program  of  the same name.  This version(1,3,5) knows more magic(4,5), however, so
       it will produce different (albeit more accurate) output in(1,8) many  cases.

       The  one  significant  difference  between this version(1,3,5) and System V is
       that this version(1,3,5) treats any white space as a delimiter, so that spaces
       in(1,8) pattern strings must be escaped.  For example,
       >10  string(3,n)    language impress    (imPRESS data)
       in(1,8) an existing magic(4,5) file(1,n) would have to be changed to
       >10  string(3,n)    language\ impress   (imPRESS data)
       In addition, in(1,8) this version(1,3,5), if(3,n) a pattern string(3,n) contains a backslash,
       it must be escaped.  For example
       0    string(3,n)         \begindata     Andrew Toolkit document
       in(1,8) an existing magic(4,5) file(1,n) would have to be changed to
       0    string(3,n)         \\begindata    Andrew Toolkit document

       SunOS releases 3.2 and later from Sun Microsystems  include  a  file(1,n)(1)
       command  derived  from  the System V one, but with some extensions.  My
       version(1,3,5) differs from Sun's only in(1,8) minor ways.  It includes the  exten-
       sion of the `&' operator, used as, for example,
       >16  long&0x7fffffff     >0        not stripped

       The magic(4,5) file(1,n) entries have been collected from various sources, mainly
       USENET, and contributed by various authors.  Christos  Zoulas  (address
       below) will collect additional or corrected magic(4,5) file(1,n) entries.  A con-
       solidation of magic(4,5) file(1,n) entries will be distributed periodically.

       The order of entries in(1,8) the magic(4,5) file(1,n) is  significant.   Depending  on
       what  system you are using, the order that they are put together may be
       incorrect.  If your old file(1,n) command uses a magic(4,5) file(1,n),  keep  the  old
       magic(4,5)   file(1,n)   around   for   comparison   purposes   (rename(1,2,n)   it   to

       $ file(1,n) file.c file(1,n) /dev/{wd0a,hda}
       file.c:   C program text
       file:     ELF 32-bit LSB executable, Intel 80386, version(1,3,5) 1 (SYSV),
                 dynamically linked (uses shared libs), stripped
       /dev/wd0a: block special (0/0)
       /dev/hda: block special (3/0)
       $ file(1,n) -s /dev/wd0{b,d}
       /dev/wd0b: data
       /dev/wd0d: x86 boot sector
       $ file(1,n) -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
       /dev/hda:   x86 boot sector
       /dev/hda1:  Linux/i386 ext2 filesystem
       /dev/hda2:  x86 boot sector
       /dev/hda3:  x86 boot sector, extended partition table
       /dev/hda4:  Linux/i386 ext2 filesystem
       /dev/hda5:  Linux/i386 swap file(1,n)
       /dev/hda6:  Linux/i386 swap file(1,n)
       /dev/hda7:  Linux/i386 swap file(1,n)
       /dev/hda8:  Linux/i386 swap file(1,n)
       /dev/hda9:  empty
       /dev/hda10: empty

       $ file(1,n) -i file.c file(1,n) /dev/{wd0a,hda}
       file.c:      text/x-c
       file:        application/x-executable, dynamically linked (uses shared libs),
       not stripped
       /dev/hda:    application/x-not-regular-file
       /dev/wd0a:   application/x-not-regular-file

       There has been a file(1,n) command in(1,8) every UNIX  since  at  least  Research
       Version 4 (man(1,5,7) page dated November, 1973).  The System V version(1,3,5) intro-
       duced one significant major change: the external list of  magic(4,5)  number
       types.   This  slowed  the program down slightly but made it a lot more

       This program, based on the System V version(1,3,5), was written by Ian  Darwin
       <> without looking at anybody else's source code.

       John  Gilmore  revised  the code extensively, making it better than the
       first version.  Geoff Collyer found several inadequacies  and  provided
       some  magic(4,5)  file(1,n)  entries.   Contributions  by the `&' operator by Rob
       McMahon,, 1989.

       Guy Harris,, made many changes from 1993 to the present.

       Primary  development and maintenance from 1990 to the present by Chris-
       tos Zoulas (

       Altered by Chris Lowth,, 2000: Handle the ``-i'' option
       to  output  mime  type  strings and using an alternative magic(4,5) file(1,n) and
       internal logic.

       Altered by Eric Fischer (, July, 2000, to identify  char-
       acter codes and attempt to identify the languages of non-ASCII files.

       The  list  of  contributors  to  the "Magdir" directory (source for the
       /etc/magic(4,5) file(1,n)) is too long to include here.  You know  who  you  are;
       thank you.

       Copyright  (c)  Ian  F. Darwin, Toronto, Canada, 1986-1999.  Covered by
       the standard Berkeley Software Distribution  copyright;  see  the  file(1,n)
       LEGAL.NOTICE in(1,8) the source distribution.

       The files tar.h and is_tar.c were written by John Gilmore from his pub-
       lic-domain tar program, and are not covered by the above license.

       There must be a better way to automate the construction  of  the  Magic
       file(1,n)  from  all the glop in(1,8) magdir.  What is it?  Better yet, the magic(4,5)
       file(1,n) should be compiled into  binary  (say,  ndbm(3)  or,  better  yet,
       fixed-length  ASCII  strings  for  use in(1,8) heterogenous network environ-
       ments) for faster startup.  Then the program would run as fast  as  the
       Version  7 program of the same name, with the flexibility of the System
       V version.

       File uses several algorithms that favor speed over  accuracy,  thus  it
       can be misled about the contents of text files.

       The  support  for  text  files (primarily for programming languages) is
       simplistic, inefficient and requires recompilation to update.

       There should be an ``else'' clause to follow a series  of  continuation

       The  magic(4,5)  file(1,n)  and  keywords should have regular expression support.
       Their use of ASCII TAB as a field delimiter is ugly and makes  it  hard
       to edit the files, but is entrenched.

       It might be advisable to allow upper-case letters in(1,8) keywords for e.g.,
       troff(1) commands vs man(1,5,7) page macros.  Regular expression support would
       make this easy.

       The  program doesn't grok FORTRAN.  It should be able to figure FORTRAN
       by seeing some keywords which appear indented at  the  start  of  line.
       Regular expression support would make this easy.

       The  list  of  keywords in(1,8) ascmagic probably belongs in(1,8) the Magic file.
       This could be done by using some keyword like `*' for the offset value.

       Another  optimisation  would  be  to sort(1,3) the magic(4,5) file(1,n) so that we can
       just run down all the tests for the first byte, first word, first long,
       etc,  once  we  have fetched it.  Complain about conflicts in(1,8) the magic(4,5)
       file(1,n) entries.  Make a rule that the magic(4,5) entries sort(1,3)  based  on  file(1,n)
       offset rather than position within the magic(4,5) file(1,n)?

       The  program should provide a way to give an estimate of ``how good'' a
       guess is.  We end up removing guesses (e.g. ``From '' as first 5  chars
       of  file(1,n))  because  they are not as good as other guesses (e.g. ``News-
       groups:'' versus ``Return-Path:'').  Still, if(3,n)  the  others  don't  pan
       out, it should be possible to use the first guess.

       This  program is slower than some vendors' file(1,n) commands.  The new sup-
       port for multiple character codes makes it even slower.

       This manual page, and particularly this section, is too long.

       You can obtain the original author's latest version(1,3,5) by anonymous FTP on in(1,8) the directory /pub/file(1,n)/file-X.YZ.tar.gz

                          Copyright but distributable                  FILE(1)

References for this manual (incoming links)