643 lines
24 KiB
HTML
643 lines
24 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>file</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="file"></a> <a name="tag_04_54"></a><!-- file -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_04_54_01"></a>NAME</h4>
|
|
|
|
<blockquote>file - determine file type</blockquote>
|
|
|
|
<h4><a name="tag_04_54_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<div class="box"><code><tt><sup>[<a href="javascript:open_code('UP')">UP</a>]</sup> <img src="../images/opt-start.gif" alt=
|
|
"[Option Start]" border="0"> file</tt> <b>[</b><tt>-dhi</tt><b>][</b><tt>-M</tt> <i>file</i><b>][</b><tt>-m</tt>
|
|
<i>file</i><b>]</b> <i>file</i> <tt>... <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>file</i> utility shall perform a series of tests on each specified <i>file</i> in an attempt to classify it:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>If the file is not a regular file, its file type shall be identified. The file types directory, FIFO, socket, block special, and
|
|
character special shall be identified as such. Other implementation-defined file types may also be identified.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If the file is a regular file, and:</p>
|
|
|
|
<ol type="a">
|
|
<li>
|
|
<p>The file is zero-length, it shall be identified as an empty file.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The file is not zero-length, <i>file</i> shall examine an initial segment of the file and shall make a guess at identifying its
|
|
contents or whether it is an executable binary file. (The answer is not guaranteed to be correct.)</p>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>If <i>file</i> does not exist, cannot be read, or its file status could not be determined, the output shall indicate that the
|
|
file was processed, but that its type could not be determined.</p>
|
|
|
|
<p>If <i>file</i> is a symbolic link, by default the link shall be resolved and <i>file</i> shall test the type of file referenced
|
|
by the symbolic link.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_04"></a>OPTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>file</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p>
|
|
|
|
<p>The following options shall be supported by the implementation:</p>
|
|
|
|
<dl compact>
|
|
<dt><b>-d</b></dt>
|
|
|
|
<dd>Apply any default system tests to the file.</dd>
|
|
|
|
<dt><b>-h</b></dt>
|
|
|
|
<dd>When a symbolic link is encountered, identify the file as a symbolic link. If <b>-h</b> is not specified and <i>file</i> is a
|
|
symbolic link that refers to a nonexistent file, <i>file</i> shall identify the file as a symbolic link, as if <b>-h</b> had been
|
|
specified.</dd>
|
|
|
|
<dt><b>-i</b></dt>
|
|
|
|
<dd>If a file is a regular file, do not attempt to classify the type of the file further, but identify the file as specified in the
|
|
STDOUT section, using a <<i>type</i>> string that contains the string <tt>"regular file"</tt> .</dd>
|
|
|
|
<dt><b>-M </b> <i>file</i></dt>
|
|
|
|
<dd>Specify the name of a file containing tests that shall be applied to a file in order to classify it (see the EXTENDED
|
|
DESCRIPTION). No default system tests shall be applied.</dd>
|
|
|
|
<dt><b>-m </b> <i>file</i></dt>
|
|
|
|
<dd>Specify the name of a file containing tests that shall be applied to a file in order to classify it (see the EXTENDED
|
|
DESCRIPTION).</dd>
|
|
</dl>
|
|
|
|
<p>If multiple instances of the <b>-m</b>, <b>-d</b>, or <b>-M</b> options are specified, the concatenation of the tests specified,
|
|
in the order specified, shall be the set of tests that are applied. If a <b>-M</b> option is specified, no tests other than those
|
|
specified using the <b>-d</b>, <b>-M</b>, and <b>-m</b> options shall be applied to the file. If neither the <b>-d</b> nor
|
|
<b>-M</b> options are specified, any default system tests shall be applied after any tests specified using the <b>-m</b>
|
|
option.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_05"></a>OPERANDS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following operand shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>file</i></dt>
|
|
|
|
<dd>A pathname of a file to be tested.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_06"></a>STDIN</h4>
|
|
|
|
<blockquote>
|
|
<p>Not used.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_07"></a>INPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>file</i> can be any file type.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_08"></a>ENVIRONMENT VARIABLES</h4>
|
|
|
|
<blockquote>
|
|
<p>The following environment variables shall affect the execution of <i>file</i>:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>LANG</i></dt>
|
|
|
|
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
|
|
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
|
|
|
|
<dt><i>LC_ALL</i></dt>
|
|
|
|
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
|
|
|
|
<dt><i>LC_CTYPE</i></dt>
|
|
|
|
<dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
|
|
opposed to multi-byte characters in arguments and input files).</dd>
|
|
|
|
<dt><i>LC_MESSAGES</i></dt>
|
|
|
|
<dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and
|
|
informative messages written to standard output.</dd>
|
|
|
|
<dt><i>NLSPATH</i></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_09"></a>ASYNCHRONOUS EVENTS</h4>
|
|
|
|
<blockquote>
|
|
<p>Default.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_10"></a>STDOUT</h4>
|
|
|
|
<blockquote>
|
|
<p>In the POSIX locale, the following format shall be used to identify each operand, <i>file</i> specified:</p>
|
|
|
|
<pre>
|
|
<tt>"%s: %s\n", <</tt><i>file</i><tt>>, <</tt><i>type</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>The values for <<i>type</i>> are unspecified, except that in the POSIX locale, if <i>file</i> is identified as one of the
|
|
types listed in the following table, <<i>type</i>> shall contain (but is not limited to) the corresponding string. Each space
|
|
shown in the strings shall be exactly one <space>.<br>
|
|
</p>
|
|
|
|
<center><b><a name="tagtcjh_14"></a> Table: File Utility Output Strings</b></center>
|
|
|
|
<center>
|
|
<table border="1" cellpadding="3" align="center">
|
|
<tr valign="top">
|
|
<th align="center">
|
|
<p class="tent"><b>If <i>file</i> is a:</b></p>
|
|
</th>
|
|
<th align="center">
|
|
<p class="tent"><b><<i>type</i>> shall contain the string:</b></p>
|
|
</th>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">Directory</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">directory</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">FIFO</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">fifo</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">Socket</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">socket</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">Block special</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">block special</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">Character special</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">character special</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">Executable binary</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">executable</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">Empty regular file</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">empty</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">Symbolic link</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">symbolic link to</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent"><i>ar</i> archive library (see <i>ar</i>)</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">archive</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">Extended <i>cpio</i> format (see <i>pax</i>)</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">cpio archive</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">Extended <i>tar</i> format (see <b>ustar</b> in <i>pax</i>)</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">tar archive</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">Shell script</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">commands text</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">C-language source</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">c program text</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">FORTRAN source</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">fortran program text</p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
|
|
<p>If <i>file</i> is identified as a symbolic link (see <b>-h</b>), the following alternative output format shall be used:</p>
|
|
|
|
<pre>
|
|
<tt>"%s: %s %s\n", <</tt><i>file</i><tt>>, <</tt><i>type</i><tt>>, <</tt><i>contents of link</i><tt>>"
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>If the file named by the <i>file</i> operand does not exist or cannot be read, the string <tt>"cannot open"</tt> shall be
|
|
included as part of the <<i>type</i>> field, but this shall not be considered an error that affects the exit status. If the
|
|
type of the file named by the <i>file</i> operand cannot be determined, the string <tt>"data"</tt> shall be included as part of the
|
|
<<i>type</i>> field, but this shall not be considered an error that affects the exit status.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_11"></a>STDERR</h4>
|
|
|
|
<blockquote>
|
|
<p>The standard error shall be used only for diagnostic messages.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_12"></a>OUTPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_13"></a>EXTENDED DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>A file specified as an option-argument to the <b>-m</b> or <b>-M</b> options shall contain one test per line, which shall be
|
|
applied to the file. If the test succeeds, the message field of the line shall be printed and no further tests shall be applied,
|
|
with the exception that tests on immediately following lines beginning with a single <tt>'>'</tt> character shall be
|
|
applied.</p>
|
|
|
|
<p>Each line shall be composed of the following four <blank>-separated fields:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>offset</i></dt>
|
|
|
|
<dd>An unsigned number (optionally preceded by a single <tt>'>'</tt> character) specifying the <i>offset</i>, in bytes, of the
|
|
value in the file that is to be compared against the <i>value</i> field of the line. If the file is shorter than the specified
|
|
offset, the test shall fail.
|
|
|
|
<p>If the <i>offset</i> begins with the character <tt>'>'</tt> , the test contained in the line shall not be applied to the file
|
|
unless the test on the last line for which the <i>offset</i> did not begin with a <tt>'>'</tt> was successful. By default, the
|
|
<i>offset</i> shall be interpreted as an unsigned decimal number. With a leading 0x or 0X, the <i>offset</i> shall be interpreted
|
|
as a hexadecimal number; otherwise, with a leading 0, the <i>offset</i> shall be interpreted as an octal number.</p>
|
|
</dd>
|
|
|
|
<dt><i>type</i></dt>
|
|
|
|
<dd>The type of the value in the file to be tested. The type shall consist of the type specification characters <tt>c</tt> ,
|
|
<tt>d</tt> , <tt>f</tt> , <tt>s</tt> , and <tt>u</tt> , specifying character, signed decimal, floating point, string, and unsigned
|
|
decimal, respectively.
|
|
|
|
<p>The <i>type</i> string shall be interpreted as the bytes from the file starting at the specified <i>offset</i> and including the
|
|
same number of bytes specified by the <i>value</i> field. If insufficient bytes remain in the file past the <i>offset</i> to match
|
|
the <i>value</i> field, the test shall fail.</p>
|
|
|
|
<p>The type specification characters <tt>d</tt> , <tt>f</tt> , and <tt>u</tt> can be followed by an optional unsigned decimal
|
|
integer that specifies the number of bytes represented by the type. The type specification character <tt>f</tt> can be followed by
|
|
an optional <tt>F</tt> , <tt>D</tt> , or <tt>L</tt> , indicating that the value is of type <b>float</b>, <b>double</b>, or <b>long
|
|
double</b>, respectively. The type specification characters <tt>d</tt> and <tt>u</tt> can be followed by an optional <tt>C</tt> ,
|
|
<tt>S</tt> , <tt>I</tt> , or <tt>L</tt> , indicating that the value is of type <b>char</b>, <b>short</b>, <b>int</b>, or
|
|
<b>long</b>, respectively.</p>
|
|
|
|
<p>The default number of bytes represented by the type specifiers <tt>d</tt> , <tt>f</tt> , and <tt>u</tt> shall correspond to
|
|
their respective C-language types as follows. If the system claims conformance to the C-Language Development Utilities option,
|
|
those specifiers shall correspond to the default sizes used in the <a href="../utilities/c99.html"><i>c99</i></a> utility.
|
|
Otherwise, the default sizes shall be implementation-defined.</p>
|
|
|
|
<p>For the type specifier characters <tt>d</tt> and <tt>u</tt> , the default number of bytes shall correspond to the size of a
|
|
basic integer type of the implementation. For these specifier characters, the implementation shall support values of the optional
|
|
number of bytes to be converted corresponding to the number of bytes in the C-language types <b>char</b>, <b>short</b>, <b>int</b>,
|
|
or <b>long</b>. These numbers can also be specified by an application as the characters <tt>C</tt> , <tt>S</tt> , <tt>I</tt> , and
|
|
<tt>L</tt> , respectively. The byte order used when interpreting numeric values is implementation-defined, but shall correspond to
|
|
the order in which a constant of the corresponding type is stored in memory on the system.</p>
|
|
|
|
<p>For the type specifier <tt>f</tt> , the default number of bytes shall correspond to the number of bytes in the basic double
|
|
precision floating-point data type of the underlying implementation. The implementation shall support values of the optional number
|
|
of bytes to be converted corresponding to the number of bytes in the C-language types <b>float</b>, <b>double</b>, and <b>long
|
|
double</b>. These numbers can also be specified by an application as the characters <tt>F</tt> , <tt>D</tt> , and <tt>L</tt> ,
|
|
respectively.</p>
|
|
|
|
<p>All type specifiers, except for <tt>s</tt> , can be followed by a mask specifier of the form &<i>number</i>. The mask value
|
|
shall be AND'ed with the value of the input file before the comparison with the <i>value</i> field of the line is made. By default,
|
|
the mask shall be interpreted as an unsigned decimal number. With a leading 0x or 0X, the mask shall be interpreted as an unsigned
|
|
hexadecimal number; otherwise, with a leading 0, the mask shall be interpreted as an unsigned octal number.</p>
|
|
|
|
<p>The strings <b>byte</b>, <b>short</b>, <b>long</b>, and <b>string</b> shall also be supported as type fields, being interpreted
|
|
as <tt>dC</tt> , <tt>dS</tt> , <tt>dL</tt> , and <tt>s</tt> , respectively.</p>
|
|
</dd>
|
|
|
|
<dt><i>value</i></dt>
|
|
|
|
<dd>The <i>value</i> to be compared with the value from the file.
|
|
|
|
<p>If the specifier from the type field is <tt>s</tt> or <b>string</b>, then interpret the value as a string. Otherwise, interpret
|
|
it as a number. If the value is a string, then the test shall succeed only when a string value exactly matches the bytes from the
|
|
file.</p>
|
|
|
|
<p>If the <i>value</i> is a string, it can contain the following sequences:</p>
|
|
|
|
<dl compact>
|
|
<dt>\<i>character</i></dt>
|
|
|
|
<dd>The backslash-escape sequences as specified in the Base Definitions volume of IEEE Std 1003.1-2001, Table 5-1, Escape
|
|
Sequences and Associated Actions ( <tt>'\\'</tt> , <tt>'\a'</tt> , <tt>'\b'</tt> , <tt>'\f'</tt> , <tt>'\n'</tt> , <tt>'\r'</tt> ,
|
|
<tt>'\t'</tt> , <tt>'\v'</tt> ). The results of using any other character, other than an octal digit, following the backslash are
|
|
unspecified.</dd>
|
|
|
|
<dt>\<i>octal</i></dt>
|
|
|
|
<dd>Octal sequences that can be used to represent characters with specific coded values. An octal sequence shall consist of a
|
|
backslash followed by the longest sequence of one, two, or three octal-digit characters (01234567). If the size of a byte on the
|
|
system is greater than 9 bits, the valid escape sequence used to represent a byte is implementation-defined.</dd>
|
|
</dl>
|
|
|
|
<p>By default, any value that is not a string shall be interpreted as a signed decimal number. Any such value, with a leading 0x or
|
|
0X, shall be interpreted as an unsigned hexadecimal number; otherwise, with a leading zero, the value shall be interpreted as an
|
|
unsigned octal number.</p>
|
|
|
|
<p>If the value is not a string, it can be preceded by a character indicating the comparison to be performed. Permissible
|
|
characters and the comparisons they specify are as follows:</p>
|
|
|
|
<dl compact>
|
|
<dt><tt>=</tt></dt>
|
|
|
|
<dd>The test shall succeed if the value from the file equals the <i>value</i> field.</dd>
|
|
|
|
<dt><tt><</tt></dt>
|
|
|
|
<dd>The test shall succeed if the value from the file is less than the <i>value</i> field.</dd>
|
|
|
|
<dt><tt>></tt></dt>
|
|
|
|
<dd>The test shall succeed if the value from the file is greater than the <i>value</i> field.</dd>
|
|
|
|
<dt><tt>&</tt></dt>
|
|
|
|
<dd>The test shall succeed if all of the set bits in the <i>value</i> field are set in the value from the file.</dd>
|
|
|
|
<dt><tt>^</tt></dt>
|
|
|
|
<dd>The test shall succeed if at least one of the set bits in the <i>value</i> field is not set in the value from the file.</dd>
|
|
|
|
<dt><tt>x</tt></dt>
|
|
|
|
<dd>The test shall succeed if the file is large enough to contain a value of the type specified starting at the offset
|
|
specified.</dd>
|
|
</dl>
|
|
</dd>
|
|
|
|
<dt><i>message</i></dt>
|
|
|
|
<dd>The <i>message</i> to be printed if the test succeeds. The <i>message</i> shall be interpreted using the notation for the <a
|
|
href="../utilities/printf.html"><i>printf</i></a> formatting specification; see <a href="printf.html"><i>printf</i>()</a> . If the
|
|
<i>value</i> field was a string, then the value from the file shall be the argument for the <a href=
|
|
"../utilities/printf.html"><i>printf</i></a> formatting specification; otherwise, the value from the file shall be the
|
|
argument.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_14"></a>EXIT STATUS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following exit values shall be returned:</p>
|
|
|
|
<dl compact>
|
|
<dt> 0</dt>
|
|
|
|
<dd>Successful completion.</dd>
|
|
|
|
<dt>>0</dt>
|
|
|
|
<dd>An error occurred.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_15"></a>CONSEQUENCES OF ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>Default.</p>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_04_54_16"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>file</i> utility can only be required to guess at many of the file types because only exhaustive testing can determine
|
|
some types with certainty. For example, binary data on some implementations might match the initial segment of an executable or a
|
|
<i>tar</i> archive.</p>
|
|
|
|
<p>Note that the table indicates that the output contains the stated string. Systems may add text before or after the string. For
|
|
executables, as an example, the machine architecture and various facts about how the file was link-edited may be included.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_17"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>Determine whether an argument is a binary executable file:</p>
|
|
|
|
<pre>
|
|
<tt>file "$1" | grep -Fq executable &&
|
|
printf "%s is executable.\n" "$1"
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_18"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <b>-f</b> option was omitted because the same effect can (and should) be obtained using the <a href=
|
|
"../utilities/xargs.html"><i>xargs</i></a> utility.</p>
|
|
|
|
<p>Historical versions of the <i>file</i> utility attempt to identify the following types of files: symbolic link, directory,
|
|
character special, block special, socket, <i>tar</i> archive, <i>cpio</i> archive, SCCS archive, archive library, empty, <a href=
|
|
"../utilities/compress.html"><i>compress</i></a> output, <i>pack</i> output, binary data, C source, FORTRAN source, assembler
|
|
source, <i>nroff</i>/ <i>troff</i>/ <i>eqn</i>/ <i>tbl</i> source <i>troff</i> output, shell script, C shell script, English text,
|
|
ASCII text, various executables, APL workspace, compiled terminfo entries, and CURSES screen images. Only those types that are
|
|
reasonably well specified in POSIX or are directly related to POSIX utilities are listed in the table.</p>
|
|
|
|
<p>Historical systems have used a "magic file" named <b>/etc/magic</b> to help identify file types. Because it is generally
|
|
useful for users and scripts to be able to identify special file types, the <b>-m</b> flag and a portable format for user-created
|
|
magic files has been specified. No requirement is made that an implementation of <i>file</i> use this method of identifying files,
|
|
only that users be permitted to add their own classifying tests.</p>
|
|
|
|
<p>In addition, three options have been added to historical practice. The <b>-d</b> flag has been added to permit users to cause
|
|
their tests to follow any default system tests. The <b>-i</b> flag has been added to permit users to test portably for regular
|
|
files in shell scripts. The <b>-M</b> flag has been added to permit users to ignore any default system tests.</p>
|
|
|
|
<p>The historical <b>-c</b> option was omitted as not particularly useful to users or portable shell scripts. In addition, a
|
|
reasonable implementation of the <i>file</i> utility would report any errors found each time the magic file is read.</p>
|
|
|
|
<p>The historical format of the magic file was the same as that specified by the Rationale in the ISO POSIX-2:1993 standard
|
|
for the <i>offset</i>, <i>value</i>, and <i>message</i> fields; however, it used less precise type fields than the format specified
|
|
by the current normative text. The new type field values are a superset of the historical ones.</p>
|
|
|
|
<p>The following is an example magic file:</p>
|
|
|
|
<pre>
|
|
<tt>0 short 070707 cpio archive
|
|
0 short 0143561 Byte-swapped cpio archive
|
|
0 string 070707 ASCII cpio archive
|
|
0 long 0177555 Very old archive
|
|
0 short 0177545 Old archive
|
|
0 short 017437 Old packed data
|
|
0 string \037\036 Packed data
|
|
0 string \377\037 Compacted data
|
|
0 string \037\235 Compressed data
|
|
>2 byte&0x80 >0 Block compressed
|
|
>2 byte&0x1f x %d bits
|
|
0 string \032\001 Compiled Terminfo Entry
|
|
0 short 0433 Curses screen image
|
|
0 short 0434 Curses screen image
|
|
0 string <ar> System V Release 1 archive
|
|
0 string !<arch>\n__.SYMDEF Archive random library
|
|
0 string !<arch> Archive
|
|
0 string ARF_BEGARF PHIGS clear text archive
|
|
0 long 0x137A2950 Scalable OpenFont binary
|
|
0 long 0x137A2951 Encrypted scalable OpenFont binary
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>The use of a basic integer data type is intended to allow the implementation to choose a word size commonly used by applications
|
|
on that architecture.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_19"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_20"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="ar.html"><i>ar</i></a> , <a href="ls.html"><i>ls</i></a> , <a href="pax.html"><i>pax</i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_21"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 4.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_54_22"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>This utility is marked as part of the User Portability Utilities option.</p>
|
|
|
|
<p>Options and an EXTENDED DESCRIPTION are added as specified in the IEEE P1003.2b draft standard.</p>
|
|
|
|
<p>IEEE PASC Interpretations 1003.2 #192 and #178 are applied.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|