Use more markup, use more appropriate markup. Improve wording.

Sort options and sections. Make ready for HTML output. Fix xref.
Add -0 to SYNOPSIS.
This commit is contained in:
wiz 2009-05-08 21:45:52 +00:00
parent 61e7e15ed9
commit 81ee850d25
1 changed files with 194 additions and 178 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: file.1,v 1.3 2009/05/08 17:34:34 christos Exp $
.\" $NetBSD: file.1,v 1.4 2009/05/08 21:45:52 wiz Exp $
.\"
.\" $File: file.man,v 1.79 2008/11/06 22:49:08 rrt Exp $
.Dd October 9, 2008
@ -9,18 +9,18 @@
.Nd determine file type
.Sh SYNOPSIS
.Nm
.Op Fl bchikLnNprsvz
.Op Fl -mime-type
.Op Fl -mime-encoding
.Op Fl f Ar namefile
.Op Fl 0bchikLNnprsvz
.Op Fl F Ar separator
.Op Fl f Ar namefile
.Op Fl m Ar magicfiles
.Op Fl Fl mime-encoding
.Op Fl Fl mime-type
.Ar file
.Nm
.Fl C
.Op Fl m Ar magicfile
.Nm
.Op Fl -help
.Op Fl Fl help
.Sh DESCRIPTION
This manual page documents version 5.03 of the
.Nm
@ -44,12 +44,12 @@ terminal),
.Em executable
(the file contains the result of compiling a program
in a form understandable to some
.Dv UNIX
.Tn UNIX
kernel or another),
or
.Em data
meaning anything else (data is usually
.Sq binary
.Dq binary
or non-printable).
Exceptions are well-known file formats (core files, tar archives)
that are known to contain binary data.
@ -57,12 +57,12 @@ When modifying magic files or the program itself, make sure to
.Em "preserve these keywords" .
Users depend on knowing that all the readable files in a directory
have the word
.Sq text
.Dq text
printed.
Don't do as Berkeley did and change
.Sq shell commands text
.Dq shell commands text
to
.Sq shell script .
.Dq shell script .
.Pp
The filesystem tests are based on examining the return from a
.Xr stat 2
@ -72,8 +72,7 @@ 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 that
implement them)
are intuited if they are defined in
the system header file
are intuited if they are defined in the system header file
.In sys/stat.h .
.Pp
The magic tests are used to check for files with data in
@ -87,13 +86,14 @@ and possibly
.In exec.h
in the standard include directory.
These files have a
.Sq "magic number"
.Dq "magic number"
stored in a particular place
near the beginning of the file that tells the
.Dv UNIX operating system
.Tn UNIX
operating system
that the file is a binary executable, and which of several types thereof.
The concept of a
.Sq "magic"
.Dq "magic"
has been applied by extension to data files.
Any file with some invariant identifier at a small fixed
offset into the file can usually be described in this way.
@ -102,7 +102,8 @@ magic file
.Pa /usr/share/misc/magic.mgc ,
or the files in the directory
.Pa /usr/share/misc/magic
if the compiled file does not exist. In addition, if
if the compiled file does not exist.
In addition, if
.Pa $HOME/.magic.mgc
or
.Pa $HOME/.magic
@ -119,10 +120,10 @@ in 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 identified
as
.Sq text
.Dq text
because they will be mostly readable on nearly any terminal;
UTF-16 and EBCDIC are only
.Sq character data
.Dq character data
because, while
they contain text, it is text that will require translation
before it can be read.
@ -140,8 +141,8 @@ has determined the character set used in a text-type file,
it will
attempt to determine in what language the file is written.
The language tests look for particular strings (cf.
.In names.h
) that can appear anywhere in the first few blocks of a file.
.In names.h )
that can appear anywhere in the first few blocks of a file.
For example, the keyword
.Em .br
indicates that the file is most likely a
@ -158,32 +159,41 @@ archives).
.Pp
Any file that cannot be identified as having been written
in any of the character sets listed above is simply said to be
.Sq data .
.Dq data .
.Sh OPTIONS
.Bl -tag -width indent
.It Fl b , -brief
.It Fl 0 , -print0
Output a null character
.Sq \e0
after the end of the filename.
Nice to
.Xr cut 1
the output.
This does not affect the separator which is still printed.
.It Fl b , Fl Fl brief
Do not prepend filenames to output lines (brief mode).
.It Fl c , -checking-printout
.It Fl c , Fl Fl checking-printout
Cause a checking printout of the parsed form of the magic file.
This is usually used in conjunction with the
.Fl m
flag to debug a new magic file before installing it.
.It Fl C , -compile
.It Fl C , Fl Fl compile
Write a
.Pa magic.mgc
output file that contains a pre-parsed version of the magic file or directory.
.It Fl e , -exclude Ar testname
.It Fl e , Fl Fl exclude Ar testname
Exclude the test named in
.Ar testname
from the list of tests made to determine the file type. Valid test names
are:
from the list of tests made to determine the file type.
Valid test names are:
.Bl -tag -width compress
.It apptype
.Dv EMX
application type (only on EMX).
.It text
Various types of text files (this test will try to guess the text encoding, irrespective of the setting of the
.Sq encoding
Various types of text files (this test will try to guess the text
encoding, irrespective of the setting of the
.Dq encoding
option).
.It encoding
Different text encodings for soft magic tests.
@ -200,7 +210,12 @@ Consults magic files.
.It tar
Examines tar files.
.El
.It Fl f , -files-from Ar namefile
.It Fl F , Fl Fl separator Ar separator
Use the specified string as the separator between the filename and the
file result returned.
Defaults to
.Sq \&: .
.It Fl f , Fl Fl files-from Ar namefile
Read the names of the files to be examined from
.Ar namefile
(one per line)
@ -211,71 +226,77 @@ or at least one filename argument must be present;
to test the standard input, use
.Sq -
as a filename argument.
.It Fl F , -separator Ar separator
Use the specified string as the separator between the filename and the
file result returned. Defaults to
.Sq \&: .
.It Fl h , -no-dereference
option causes symlinks not to be followed
(on systems that support symbolic links). This is the default if the
environment variable
.Dv POSIXLY_CORRECT
.It Fl h , Fl Fl no-dereference
Do not follow symlinks
(on systems that support symbolic links).
This is the default if the environment variable
.Ev POSIXLY_CORRECT
is not defined.
.It Fl i , -mime
Causes the file command to output mime type strings rather than the more
traditional human readable ones. Thus it may say
.Sq text/plain; charset=us-ascii
.It Fl Fl help
Print a help message and exit.
.It Fl i , Fl Fl mime
Output mime type strings rather than the more
traditional human readable ones.
Thus
.Nm
may say
.Dq text/plain; charset=us-ascii
rather than
.Sq ASCII text .
In order for this option to work, file changes the way
.Dq ASCII text .
In order for this option to work,
.Nm
changes the way
it handles files recognized by the command itself (such as many of the
text file types, directories etc), and makes use of an alternative
.Sq magic
.Dq magic
file.
(See the FILES section, below).
.It Fl -mime-type , -mime-encoding
(See the
.Sx FILES
section, below).
.It Fl Fl mime-type , Fl Fl mime-encoding
Like
.Fl i ,
but print only the specified element(s).
.It Fl k , -keep-going
Don't stop at the first match, keep going. Subsequent matches will be
have the string
.Sq "\[rs]012\- "
.It Fl k , Fl Fl keep-going
Don't stop at the first match, keep going.
Subsequent matches will have the string
.Dq "\[rs]012\- "
prepended.
(If you want a newline, see the
.Sq "\-r"
.Fl r
option.)
.It Fl L , -dereference
option causes symlinks to be followed, as the like-named option in
.It Fl L , Fl Fl dereference
Follow symlinks, 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_CORRECT
.Ev POSIXLY_CORRECT
is defined.
.It Fl m , -magic-file Ar list
.It Fl m , Fl Fl magic-file Ar list
Specify an alternate list of files and directories containing magic.
This can be a single item, or a colon-separated list.
If a compiled magic file is found alongside a file or directory, it will be used instead.
.It Fl n , -no-buffer
If a compiled magic file is found alongside a file or directory,
it will be used instead.
.It Fl N , Fl Fl no-pad
Don't pad filenames so that they align in the output.
.It Fl n , Fl Fl no-buffer
Force 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-pad
Don't pad filenames so that they align in the output.
.It Fl p , -preserve-date
.It Fl p , Fl Fl preserve-date
On systems that support
.Xr utime 2
.Xr utime 3
or
.Xr utimes 2 ,
attempt to preserve the access time of files analyzed, to pretend that
.Nm
never read them.
.It Fl r , -raw
.It Fl r , Fl Fl raw
Don't translate unprintable characters to \eooo.
Normally
.Nm
translates unprintable characters to their octal representation.
.It Fl s , -special-files
.It Fl s , Fl Fl special-files
Normally,
.Nm
only attempts to read and determine the type of argument files which
@ -295,29 +316,17 @@ This option also causes
to disregard the file size as reported by
.Xr stat 2
since on some systems it reports a zero size for raw disk partitions.
.It Fl v , -version
.It Fl v , Fl Fl version
Print the version of the program and exit.
.It Fl z , -uncompress
.It Fl z , Fl Fl uncompress
Try to look inside compressed files.
.It Fl 0 , -print0
Output a null character
.Sq \e0
after the end of the filename. Nice to
.Xr cut 1
the output. This does not affect the separator which is still printed.
.It Fl -help
Print a help message and exit.
.El
.Sh FILES
.Bl -tag -width /usr/share/misc/magic.mgc -compact
.It Pa /usr/share/misc/magic.mgc
Default compiled list of magic.
.It Pa /usr/share/misc/magic
Directory containing default magic files.
.El
.Sh RETURN VALUES
.Nm
returns 0 on success, and non-zero on error.
.Sh ENVIRONMENT
The environment variable
.Dv MAGIC
.Ev MAGIC
can be used to set the default magic file name.
If that variable is set, then
.Nm
@ -325,89 +334,28 @@ will not attempt to open
.Pa $HOME/.magic .
.Nm
adds
.Sq .mgc
.Dq Pa .mgc
to the value of this variable as appropriate.
The environment variable
.Dv POSIXLY_CORRECT
.Ev POSIXLY_CORRECT
controls (on systems that support symbolic links), whether
.Nm
will attempt to follow symlinks or not. If set, then
will attempt to follow symlinks or not.
If set, then
.Nm
follows symlink, otherwise it does not. This is also controlled
by the
follows symlink, otherwise it does not.
This is also controlled by the
.Fl L
and
.Fl h
options.
.Sh SEE ALSO
.Xr magic 5 ,
.Xr strings 1 ,
.Xr od 1 ,
.Xr hexdump 1,
.Xr file 1posix
.Sh STANDARDS CONFORMANCE
This program is believed to exceed the System V Interface Definition
of FILE(CMD), as near as one can determine from the vague language
contained therein.
Its behavior is mostly compatible with the System V program of the same name.
This version knows more magic, however, so it will produce
different (albeit more accurate) output in many cases.
.\" URL: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html
.Pp
The one significant difference
between this version and System V
is that this version treats any white space
as a delimiter, so that spaces in pattern strings must be escaped.
For example,
.Bd -literal -offset indent
>10 string language impress\ (imPRESS data)
.Ed
.Pp
in an existing magic file would have to be changed to
.Bd -literal -offset indent
>10 string language\e impress (imPRESS data)
.Ed
.Pp
In addition, in this version, if a pattern string contains a backslash,
it must be escaped.
For example
.Bd -literal -offset indent
0 string \ebegindata Andrew Toolkit document
.Ed
.Pp
in an existing magic file would have to be changed to
.Bd -literal -offset indent
0 string \e\ebegindata Andrew Toolkit document
.Ed
.Pp
SunOS releases 3.2 and later from Sun Microsystems include a
.Nm
command derived from the System V one, but with some extensions.
My version differs from Sun's only in minor ways.
It includes the extension of the
.Sq &
operator, used as,
for example,
.Bd -literal -offset indent
>16 long&0x7fffffff >0 not stripped
.Ed
.Sh MAGIC DIRECTORY
The magic file entries have been collected from various sources,
mainly USENET, and contributed by various authors.
Christos Zoulas (address below) will collect additional
or corrected magic file entries.
A consolidation of magic file entries
will be distributed periodically.
.Pp
The order of entries in the magic file is significant.
Depending on what system you are using, the order that
they are put together may be incorrect.
If your old
.Nm
command uses a magic file,
keep the old magic file around for comparison purposes
(rename it to
.Pa /usr/share/misc/magic.orig ).
.Sh FILES
.Bl -tag -width /usr/share/misc/magic.mgc -compact
.It Pa /usr/share/misc/magic.mgc
Default compiled list of magic.
.It Pa /usr/share/misc/magic
Directory containing default magic files.
.El
.Sh EXAMPLES
.Bd -literal -offset indent
$ file file.c file /dev/{wd0a,hda}
@ -441,6 +389,74 @@ file: application/x-executable
/dev/wd0a: application/x-not-regular-file
.Ed
.Sh SEE ALSO
.Xr hexdump 1 ,
.Xr od 1 ,
.Xr strings 1 ,
.Xr magic 5
.Sh STANDARDS
This program is believed to exceed the System V Interface Definition
of FILE(CMD), as near as one can determine from the vague language
contained therein.
Its behavior is mostly compatible with the System V program of the same name.
This version knows more magic, however, so it will produce
different (albeit more accurate) output in many cases.
.\" URL: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html
.Pp
The one significant difference
between this version and System V
is that this version treats any white space
as a delimiter, so that spaces in pattern strings must be escaped.
For example,
.Bd -literal -offset indent
\*[Gt]10 string language impress\ (imPRESS data)
.Ed
.Pp
in an existing magic file would have to be changed to
.Bd -literal -offset indent
\*[Gt]10 string language\e impress (imPRESS data)
.Ed
.Pp
In addition, in this version, if a pattern string contains a backslash,
it must be escaped.
For example
.Bd -literal -offset indent
0 string \ebegindata Andrew Toolkit document
.Ed
.Pp
in an existing magic file would have to be changed to
.Bd -literal -offset indent
0 string \e\ebegindata Andrew Toolkit document
.Ed
.Pp
SunOS releases 3.2 and later from Sun Microsystems include a
.Nm
command derived from the System V one, but with some extensions.
This version differs from Sun's only in minor ways.
It includes the extension of the
.Sq \*[Am]
operator, used as,
for example,
.Bd -literal -offset indent
\*[Gt]16 long\*[Am]0x7fffffff \*[Gt]0 not stripped
.Ed
.Sh MAGIC DIRECTORY
The magic file entries have been collected from various sources,
mainly USENET, and contributed by various authors.
Christos Zoulas (address below) will collect additional
or corrected magic file entries.
A consolidation of magic file entries
will be distributed periodically.
.Pp
The order of entries in the magic file is significant.
Depending on what system you are using, the order that
they are put together may be incorrect.
If your old
.Nm
command uses a magic file,
keep the old magic file around for comparison purposes
(rename it to
.Pa /usr/share/misc/magic.orig ) .
.Sh HISTORY
There has been a
.Nm
@ -452,19 +468,23 @@ the external list of magic types.
This slowed the program down slightly but made it a lot more flexible.
.Pp
This program, based on the System V version,
was written by Ian Darwin <ian@darwinsys.com>
was written by Ian Darwin
.Aq ian@darwinsys.com
without looking at anybody else's source code.
.Pp
John Gilmore revised the code extensively, making it better than
the first version.
Geoff Collyer found several inadequacies
and provided some magic file entries.
Contributions by the `&' operator by Rob McMahon, cudcv@warwick.ac.uk, 1989.
Contributions by the
.Sq \*[Am]
operator by Rob McMahon, cudcv@warwick.ac.uk, 1989.
.Pp
Guy Harris, guy@netapp.com, made many changes from 1993 to the present.
.Pp
Primary development and maintenance from 1990 to the present by
Christos Zoulas (christos@astron.com).
Christos Zoulas
.Aq christos@astron.com .
.Pp
Altered by Chris Lowth, chris@lowth.com, 2000:
Handle the
@ -472,11 +492,15 @@ Handle the
option to output mime type strings, using an alternative
magic file and internal logic.
.Pp
Altered by Eric Fischer (enf@pobox.com), July, 2000,
Altered by Eric Fischer
.Aq enf@pobox.com ,
July, 2000,
to identify character codes and attempt to identify the languages
of non-ASCII files.
.Pp
Altered by Reuben Thomas (rrt@sc3d.org), 2007 to 2008, to improve MIME
Altered by Reuben Thomas
.Aq rrt@sc3d.org ,
2007 to 2008, to improve MIME
support and merge MIME and non-MIME magic, support directories as well
as files of magic, apply many bug fixes and improve the build system.
.Pp
@ -492,23 +516,20 @@ Covered by the standard Berkeley Software Distribution copyright; see the file
LEGAL.NOTICE in the source distribution.
.Pp
The files
.Dv tar.h
.Pa tar.h
and
.Dv is_tar.c
.Pa is_tar.c
were written by John Gilmore from his public-domain
.Xr tar 1
program, and are not covered by the above license.
.Sh BUGS
.Pp
There must be a better way to automate the construction of the Magic
file from all the glop in Magdir.
What is it?
.Pp
.Nm
uses several algorithms that favor speed over accuracy,
thus it can be misled about the contents of
text
files.
thus it can be misled about the contents of text files.
.Pp
The support for text files (primarily for programming languages)
is simplistic, inefficient and requires recompilation to update.
@ -524,8 +545,7 @@ Complain about conflicts in the magic file entries.
Make a rule that the magic entries sort based on file offset rather
than position within the magic file?
.Pp
The program should provide a way to give an estimate
of
The program should provide a way to give an estimate of
.Sq how good
a guess is.
We end up removing guesses (e.g.
@ -534,18 +554,14 @@ as first 5 chars of file) because
they are not as good as other guesses (e.g.
.Sq Newsgroups:
versus
.Sq Return-Path:
).
.Sq Return-Path: ) .
Still, if the others don't pan out, it should be possible to use the
first guess.
.Pp
This manual page, and particularly this section, is too long.
.Sh RETURN CODE
.Nm
returns 0 on success, and non-zero on error.
.Sh AVAILABILITY
You can obtain the original author's latest version by anonymous FTP
on
.Dv ftp.astron.com
.Pa ftp.astron.com
in the directory
.Dv /pub/file/file-X.YZ.tar.gz
.Pa /pub/file/file-X.YZ.tar.gz .