isposix

Un outil pour savoir si une commande est posix - retour accueil

git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |

file.html (35816B)


      1 <!-- Copyright 2001-2024 IEEE and The Open Group, All Rights Reserved -->
      2 <!DOCTYPE HTML>
      3 <html lang="en">
      4 <head>
      5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.8.0">
      6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      7 <link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group rhtm tool v1.2.4 -->
      8 <!-- Copyright (c) 2001-2024 The Open Group, All Rights Reserved -->
      9 <title>file</title>
     10 </head>
     11 <body bgcolor="white">
     12 <div class="NAVHEADER">
     13 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
     14 <tr class="nav">
     15 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/fg.html" accesskey="P">&lt;&lt;&lt;
     16 Previous</a></td>
     17 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
     18 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/find.html" accesskey="N">Next &gt;&gt;&gt;</a></td>
     19 </tr>
     20 </table>
     21 <hr align="left" width="100%"></div>
     22 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3">
     23 <center><font size="2">The Open Group Base Specifications Issue 8<br>
     24 IEEE Std 1003.1-2024<br>
     25 Copyright © 2001-2024 The IEEE and The Open Group</font></center>
     26 <hr size="2" noshade>
     27 <a name="top" id="top"></a> <a name="file" id="file"></a> <a name="tag_20_46" id="tag_20_46"></a><!-- file -->
     28 <h4 class="mansect"><a name="tag_20_46_01" id="tag_20_46_01"></a>NAME</h4>
     29 <blockquote>file — determine file type</blockquote>
     30 <h4 class="mansect"><a name="tag_20_46_02" id="tag_20_46_02"></a>SYNOPSIS</h4>
     31 <blockquote class="synopsis">
     32 <p><code><tt>file</tt> <b>[</b><tt>-dh</tt><b>] [</b><tt>-M</tt> <i>file</i><b>] [</b><tt>-m</tt> <i>file</i><b>]</b>
     33 <i>file</i><tt>...<br>
     34 <br>
     35 file -i</tt> <b>[</b><tt>-h</tt><b>]</b> <i>file</i><tt>...<br></tt></code></p>
     36 </blockquote>
     37 <h4 class="mansect"><a name="tag_20_46_03" id="tag_20_46_03"></a>DESCRIPTION</h4>
     38 <blockquote>
     39 <p>The <i>file</i> utility shall perform a series of tests in sequence on each specified <i>file</i> in an attempt to classify
     40 it:</p>
     41 <ol>
     42 <li>
     43 <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
     44 file was processed, but that its type could not be determined.</p>
     45 </li>
     46 <li>
     47 <p>If the file is not a regular file, its file type shall be identified. The file types directory, FIFO, socket, block special, and
     48 character special shall be identified as such. Other implementation-defined file types may also be identified. If <i>file</i> is a
     49 symbolic link, by default the link shall be resolved and <i>file</i> shall test the type of file referenced by the symbolic link.
     50 (See the <b>-h</b> and <b>-i</b> options below.)</p>
     51 </li>
     52 <li>
     53 <p>If the length of <i>file</i> is zero, it shall be identified as an empty file.</p>
     54 </li>
     55 <li>
     56 <p>The <i>file</i> utility shall examine an initial segment of <i>file</i> and shall make a guess at identifying its contents based
     57 on position-sensitive tests. (The answer is not guaranteed to be correct; see the <b>-d</b>, <b>-M</b>, and <b>-m</b> options
     58 below.)</p>
     59 </li>
     60 <li>
     61 <p>The <i>file</i> utility shall examine <i>file</i> and make a guess at identifying its contents based on context-sensitive
     62 default system tests. (The answer is not guaranteed to be correct.)</p>
     63 </li>
     64 <li>
     65 <p>The file shall be identified as a data file.</p>
     66 </li>
     67 </ol>
     68 <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
     69 file was processed, but that its type could not be determined.</p>
     70 <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
     71 by the symbolic link.</p>
     72 </blockquote>
     73 <h4 class="mansect"><a name="tag_20_46_04" id="tag_20_46_04"></a>OPTIONS</h4>
     74 <blockquote>
     75 <p>The <i>file</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax
     76 Guidelines</i></a> , except that the order of the <b>-m</b>, <b>-d</b>, and <b>-M</b> options shall be significant.</p>
     77 <p>The following options shall be supported by the implementation:</p>
     78 <dl compact>
     79 <dd></dd>
     80 <dt><b>-d</b></dt>
     81 <dd>Apply any position-sensitive default system tests and context-sensitive default system tests to the file. This is the default
     82 if no <b>-M</b> or <b>-m</b> option is specified.</dd>
     83 <dt><b>-h</b></dt>
     84 <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
     85 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
     86 specified.</dd>
     87 <dt><b>-i</b></dt>
     88 <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
     89 STDOUT section.</dd>
     90 <dt><b>-M&nbsp;</b><i>file</i></dt>
     91 <dd>Specify the name of a file containing position-sensitive tests that shall be applied to a file in order to classify it (see the
     92 EXTENDED DESCRIPTION). No position-sensitive default system tests nor context-sensitive default system tests shall be applied
     93 unless the <b>-d</b> option is also specified.</dd>
     94 <dt><b>-m&nbsp;</b><i>file</i></dt>
     95 <dd>Specify the name of a file containing position-sensitive tests that shall be applied to a file in order to classify it (see the
     96 EXTENDED DESCRIPTION).</dd>
     97 </dl>
     98 <p>If the <b>-m</b> option is specified without specifying the <b>-d</b> option or the <b>-M</b> option, position-sensitive default
     99 system tests shall be applied after the position-sensitive tests specified by the <b>-m</b> option. If the <b>-M</b> option is
    100 specified with the <b>-d</b> option, the <b>-m</b> option, or both, or the <b>-m</b> option is specified with the <b>-d</b> option,
    101 the concatenation of the position-sensitive tests specified by these options shall be applied in the order specified by the
    102 appearance of these options. If a <b>-M</b> or <b>-m</b> <i>file</i> option-argument is <b>-</b>, the results are unspecified.</p>
    103 </blockquote>
    104 <h4 class="mansect"><a name="tag_20_46_05" id="tag_20_46_05"></a>OPERANDS</h4>
    105 <blockquote>
    106 <p>The following operand shall be supported:</p>
    107 <dl compact>
    108 <dd></dd>
    109 <dt><i>file</i></dt>
    110 <dd>A pathname of a file to be tested.</dd>
    111 </dl>
    112 </blockquote>
    113 <h4 class="mansect"><a name="tag_20_46_06" id="tag_20_46_06"></a>STDIN</h4>
    114 <blockquote>
    115 <p>The standard input shall be used if a <i>file</i> operand is <tt>'-'</tt> and the implementation treats the <tt>'-'</tt> as
    116 meaning standard input. Otherwise, the standard input shall not be used.</p>
    117 </blockquote>
    118 <h4 class="mansect"><a name="tag_20_46_07" id="tag_20_46_07"></a>INPUT FILES</h4>
    119 <blockquote>
    120 <p>The <i>file</i> can be any file type.</p>
    121 </blockquote>
    122 <h4 class="mansect"><a name="tag_20_46_08" id="tag_20_46_08"></a>ENVIRONMENT VARIABLES</h4>
    123 <blockquote>
    124 <p>The following environment variables shall affect the execution of <i>file</i>:</p>
    125 <dl compact>
    126 <dd></dd>
    127 <dt><i>LANG</i></dt>
    128 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href=
    129 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization
    130 variables used to determine the values of locale categories.)</dd>
    131 <dt><i>LC_ALL</i></dt>
    132 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
    133 <dt><i>LC_CTYPE</i></dt>
    134 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
    135 opposed to multi-byte characters in arguments and input files).</dd>
    136 <dt><i>LC_MESSAGES</i></dt>
    137 <dd><br>
    138 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and
    139 informative messages written to standard output.</dd>
    140 <dt><i>NLSPATH</i></dt>
    141 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
    142 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border=
    143 "0"></dd>
    144 </dl>
    145 </blockquote>
    146 <h4 class="mansect"><a name="tag_20_46_09" id="tag_20_46_09"></a>ASYNCHRONOUS EVENTS</h4>
    147 <blockquote>
    148 <p>Default.</p>
    149 </blockquote>
    150 <h4 class="mansect"><a name="tag_20_46_10" id="tag_20_46_10"></a>STDOUT</h4>
    151 <blockquote>
    152 <p>In the POSIX locale, the following format shall be used to identify each operand, <i>file</i> specified:</p>
    153 <pre>
    154 <tt>"%s: %s\n", &lt;</tt><i>file</i><tt>&gt;, &lt;</tt><i>type</i><tt>&gt;
    155 </tt></pre>
    156 <p>The values for &lt;<i>type</i>&gt; are unspecified, except that in the POSIX locale, if <i>file</i> is identified as one of the
    157 types listed in the following table, &lt;<i>type</i>&gt; shall contain (but is not limited to) the corresponding string, unless the
    158 file is identified by a position-sensitive test specified by a <b>-M</b> or <b>-m</b> option. Each &lt;space&gt; shown in the
    159 strings shall be exactly one &lt;space&gt;.<br></p>
    160 <p class="caption"><a name="tagtcjh_20" id="tagtcjh_20"></a> Table: File Utility Output Strings</p>
    161 <center>
    162 <table border="1" cellpadding="3" align="center">
    163 <tr valign="top">
    164 <th align="center">
    165 <p class="tent"><b>If <i>file</i> is:</b></p>
    166 </th>
    167 <th align="center">
    168 <p class="tent"><b>&lt;<i>type</i>&gt; shall contain the string:</b></p>
    169 </th>
    170 <th align="center">
    171 <p class="tent"><b>Notes</b></p>
    172 </th>
    173 </tr>
    174 <tr valign="top">
    175 <td align="left">
    176 <p class="tent">Nonexistent</p>
    177 </td>
    178 <td align="left">
    179 <p class="tent">cannot open</p>
    180 </td>
    181 <td align="left">
    182 <p class="tent">&nbsp;</p>
    183 </td>
    184 </tr>
    185 <tr valign="top">
    186 <td align="left">
    187 <p class="tent">Block special</p>
    188 </td>
    189 <td align="left">
    190 <p class="tent">block special</p>
    191 </td>
    192 <td align="left">
    193 <p class="tent">1</p>
    194 </td>
    195 </tr>
    196 <tr valign="top">
    197 <td align="left">
    198 <p class="tent">Character special</p>
    199 </td>
    200 <td align="left">
    201 <p class="tent">character special</p>
    202 </td>
    203 <td align="left">
    204 <p class="tent">1</p>
    205 </td>
    206 </tr>
    207 <tr valign="top">
    208 <td align="left">
    209 <p class="tent">Directory</p>
    210 </td>
    211 <td align="left">
    212 <p class="tent">directory</p>
    213 </td>
    214 <td align="left">
    215 <p class="tent">1</p>
    216 </td>
    217 </tr>
    218 <tr valign="top">
    219 <td align="left">
    220 <p class="tent">FIFO</p>
    221 </td>
    222 <td align="left">
    223 <p class="tent">fifo</p>
    224 </td>
    225 <td align="left">
    226 <p class="tent">1</p>
    227 </td>
    228 </tr>
    229 <tr valign="top">
    230 <td align="left">
    231 <p class="tent">Socket</p>
    232 </td>
    233 <td align="left">
    234 <p class="tent">socket</p>
    235 </td>
    236 <td align="left">
    237 <p class="tent">1</p>
    238 </td>
    239 </tr>
    240 <tr valign="top">
    241 <td align="left">
    242 <p class="tent">Symbolic link</p>
    243 </td>
    244 <td align="left">
    245 <p class="tent">symbolic link to</p>
    246 </td>
    247 <td align="left">
    248 <p class="tent">1</p>
    249 </td>
    250 </tr>
    251 <tr valign="top">
    252 <td align="left">
    253 <p class="tent">Regular file</p>
    254 </td>
    255 <td align="left">
    256 <p class="tent">regular file</p>
    257 </td>
    258 <td align="left">
    259 <p class="tent">1,2</p>
    260 </td>
    261 </tr>
    262 <tr valign="top">
    263 <td align="left">
    264 <p class="tent">Empty regular file</p>
    265 </td>
    266 <td align="left">
    267 <p class="tent">empty</p>
    268 </td>
    269 <td align="left">
    270 <p class="tent">3</p>
    271 </td>
    272 </tr>
    273 <tr valign="top">
    274 <td align="left">
    275 <p class="tent">Regular file that cannot be read</p>
    276 </td>
    277 <td align="left">
    278 <p class="tent">cannot open</p>
    279 </td>
    280 <td align="left">
    281 <p class="tent">3</p>
    282 </td>
    283 </tr>
    284 <tr valign="top">
    285 <td align="left">
    286 <p class="tent">Executable binary</p>
    287 </td>
    288 <td align="left">
    289 <p class="tent">executable</p>
    290 </td>
    291 <td align="left">
    292 <p class="tent">3,4,6</p>
    293 </td>
    294 </tr>
    295 <tr valign="top">
    296 <td align="left">
    297 <p class="tent"><i>ar</i> archive library (see <i>ar</i>)</p>
    298 </td>
    299 <td align="left">
    300 <p class="tent">archive</p>
    301 </td>
    302 <td align="left">
    303 <p class="tent">3,4,6</p>
    304 </td>
    305 </tr>
    306 <tr valign="top">
    307 <td align="left">
    308 <p class="tent">Extended <i>cpio</i> format (see <i>pax</i>)</p>
    309 </td>
    310 <td align="left">
    311 <p class="tent">cpio archive</p>
    312 </td>
    313 <td align="left">
    314 <p class="tent">3,4,6</p>
    315 </td>
    316 </tr>
    317 <tr valign="top">
    318 <td align="left">
    319 <p class="tent">Extended <i>tar</i> format (see <b>ustar</b> in <i>pax</i>)</p>
    320 </td>
    321 <td align="left">
    322 <p class="tent">tar archive</p>
    323 </td>
    324 <td align="left">
    325 <p class="tent">3,4,6</p>
    326 </td>
    327 </tr>
    328 <tr valign="top">
    329 <td align="left">
    330 <p class="tent">Shell script</p>
    331 </td>
    332 <td align="left">
    333 <p class="tent">commands text</p>
    334 </td>
    335 <td align="left">
    336 <p class="tent">3,5,6</p>
    337 </td>
    338 </tr>
    339 <tr valign="top">
    340 <td align="left">
    341 <p class="tent">C-language source</p>
    342 </td>
    343 <td align="left">
    344 <p class="tent">c program text</p>
    345 </td>
    346 <td align="left">
    347 <p class="tent">3,5,6</p>
    348 </td>
    349 </tr>
    350 <tr valign="top">
    351 <td align="left">
    352 <p class="tent">FORTRAN source</p>
    353 </td>
    354 <td align="left">
    355 <p class="tent">fortran program text</p>
    356 </td>
    357 <td align="left">
    358 <p class="tent">3,5,6</p>
    359 </td>
    360 </tr>
    361 <tr valign="top">
    362 <td align="left">
    363 <p class="tent">Regular file whose type cannot be determined</p>
    364 </td>
    365 <td align="left">
    366 <p class="tent">data</p>
    367 </td>
    368 <td align="left">
    369 <p class="tent">3</p>
    370 </td>
    371 </tr>
    372 </table>
    373 </center>
    374 <basefont size="2">
    375 <dl>
    376 <dt><b>Notes:</b></dt>
    377 <dd>
    378 <ol>
    379 <li class="tent">This is a file type test.</li>
    380 <li class="tent">This test is applied only if the <b>-i</b> option is specified.</li>
    381 <li class="tent">This test is applied only if the <b>-i</b> option is not specified.</li>
    382 <li class="tent">This is a position-sensitive default system test.</li>
    383 <li class="tent">This is a context-sensitive default system test.</li>
    384 <li class="tent">Position-sensitive default system tests and context-sensitive default system tests are not applied if the
    385 <b>-M</b> option is specified unless the <b>-d</b> option is also specified.</li>
    386 </ol>
    387 </dd>
    388 </dl>
    389 <basefont size="3">
    390 <p class="tent">In the POSIX locale, if <i>file</i> is identified as a symbolic link (see the <b>-h</b> option), the following
    391 alternative output format shall be used:</p>
    392 <pre>
    393 <tt>"%s: %s %s\n", &lt;</tt><i>file</i><tt>&gt;, &lt;</tt><i>type</i><tt>&gt;, &lt;</tt><i>contents of link</i><tt>&gt;"
    394 </tt></pre>
    395 <p class="tent">If the file named by the <i>file</i> operand does not exist, cannot be read, or the type of the file named by the
    396 <i>file</i> operand cannot be determined, this shall not be considered an error that affects the exit status.</p>
    397 </blockquote>
    398 <h4 class="mansect"><a name="tag_20_46_11" id="tag_20_46_11"></a>STDERR</h4>
    399 <blockquote>
    400 <p>The standard error shall be used only for diagnostic messages.</p>
    401 </blockquote>
    402 <h4 class="mansect"><a name="tag_20_46_12" id="tag_20_46_12"></a>OUTPUT FILES</h4>
    403 <blockquote>
    404 <p>None.</p>
    405 </blockquote>
    406 <h4 class="mansect"><a name="tag_20_46_13" id="tag_20_46_13"></a>EXTENDED DESCRIPTION</h4>
    407 <blockquote>
    408 <p>A file specified as an option-argument to the <b>-m</b> or <b>-M</b> options shall contain one position-sensitive test per line,
    409 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
    410 be applied, with the exception that tests on immediately following lines beginning with a single <tt>'&gt;'</tt> character shall be
    411 applied.</p>
    412 <p class="tent">Each line shall be composed of the following four &lt;tab&gt;-separated fields. (Implementations may allow any
    413 combination of one or more white-space characters other than &lt;newline&gt; to act as field separators.)</p>
    414 <dl compact>
    415 <dd></dd>
    416 <dt><i>offset</i></dt>
    417 <dd>An unsigned number (optionally preceded by a single <tt>'&gt;'</tt> character) specifying the <i>offset</i>, in bytes, of the
    418 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
    419 offset, the test shall fail.
    420 <p class="tent">If the <i>offset</i> begins with the character <tt>'&gt;'</tt>, the test contained in the line shall not be applied
    421 to the file unless the test on the last line for which the <i>offset</i> did not begin with a <tt>'&gt;'</tt> was successful. By
    422 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
    423 interpreted as a hexadecimal number; otherwise, with a leading 0, the <i>offset</i> shall be interpreted as an octal number.</p>
    424 </dd>
    425 <dt><i>type</i></dt>
    426 <dd>The type of the value in the file to be tested. The type shall consist of the type specification characters <tt>d</tt>,
    427 <tt>s</tt>, and <tt>u</tt>, specifying signed decimal, string, and unsigned decimal, respectively.
    428 <p class="tent">The <i>type</i> string shall be interpreted as the bytes from the file starting at the specified <i>offset</i> and
    429 including the same number of bytes specified by the <i>value</i> field. If insufficient bytes remain in the file past the
    430 <i>offset</i> to match the <i>value</i> field, the test shall fail.</p>
    431 <p class="tent">The type specification characters <tt>d</tt> and <tt>u</tt> can be followed by an optional unsigned decimal integer
    432 that specifies the number of bytes represented by the type. The type specification characters <tt>d</tt> and <tt>u</tt> can be
    433 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>,
    434 <b>short</b>, <b>int</b>, or <b>long</b>, respectively.</p>
    435 <p class="tent">The default number of bytes represented by the type specifiers <tt>d</tt>, <tt>f</tt>, and <tt>u</tt> shall
    436 correspond to their respective C-language types as follows. If the system claims conformance to the C-Language Development
    437 Utilities option, those specifiers shall correspond to the default sizes used in the <a href="../utilities/c17.html"><i>c17</i></a>
    438 utility. Otherwise, the default sizes shall be implementation-defined.</p>
    439 <p class="tent">For the type specifier characters <tt>d</tt> and <tt>u</tt>, the default number of bytes shall correspond to the
    440 size of a basic integer type of the implementation. For these specifier characters, the implementation shall support values of the
    441 optional number of bytes to be converted corresponding to the number of bytes in the C-language types <b>char</b>, <b>short</b>,
    442 <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>,
    443 <tt>I</tt>, and <tt>L</tt>, respectively. The byte order used when interpreting numeric values is implementation-defined, but shall
    444 correspond to the order in which a constant of the corresponding type is stored in memory on the system.</p>
    445 <p class="tent">All type specifiers, except for <tt>s</tt>, can be followed by a mask specifier of the form &<i>number</i>. The
    446 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.
    447 By default, the mask shall be interpreted as an unsigned decimal number. With a leading 0x or 0X, the mask shall be interpreted as
    448 an unsigned hexadecimal number; otherwise, with a leading 0, the mask shall be interpreted as an unsigned octal number.</p>
    449 <p class="tent">The strings <b>byte</b>, <b>short</b>, <b>long</b>, and <b>string</b> shall also be supported as type fields, being
    450 interpreted as <tt>dC</tt>, <tt>dS</tt>, <tt>dL</tt>, and <tt>s</tt>, respectively.</p>
    451 </dd>
    452 <dt><i>value</i></dt>
    453 <dd>The <i>value</i> to be compared with the value from the file.
    454 <p class="tent">If the specifier from the type field is <tt>s</tt> or <b>string</b>, then interpret the value as a string.
    455 Otherwise, interpret it as a number. If the value is a string, then the test shall succeed only when a string value exactly matches
    456 the bytes from the file.</p>
    457 <p class="tent">If the <i>value</i> is a string, it can contain the following sequences:</p>
    458 <dl compact>
    459 <dd></dd>
    460 <dt>\<i>character</i></dt>
    461 <dd>The &lt;backslash&gt;-escape sequences as specified in XBD <a href="../basedefs/V1_chap05.html#tagtcjh_2"><i>Escape Sequences
    462 and Associated Actions</i></a> (<tt>'\\'</tt>, <tt>'\a'</tt>, <tt>'\b'</tt>, <tt>'\f'</tt>, <tt>'\n'</tt>, <tt>'\r'</tt>,
    463 <tt>'\t'</tt>, <tt>'\v'</tt>). In addition, the escape sequence <tt>'\&nbsp;'</tt> (the &lt;backslash&gt; character followed by a
    464 &lt;space&gt; character) shall be recognized to represent a &lt;space&gt; character. The results of using any other character,
    465 other than an octal digit, following the &lt;backslash&gt; are unspecified.</dd>
    466 <dt>\<i>octal</i></dt>
    467 <dd>Octal sequences that can be used to represent characters with specific coded values. An octal sequence shall consist of a
    468 &lt;backslash&gt; followed by the longest sequence of one, two, or three octal-digit characters (01234567).</dd>
    469 </dl>
    470 <p class="tent">By default, any value that is not a string shall be interpreted as a signed decimal number. Any such value, with a
    471 leading 0x or 0X, shall be interpreted as an unsigned hexadecimal number; otherwise, with a leading zero, the value shall be
    472 interpreted as an unsigned octal number.</p>
    473 <p class="tent">If the value is not a string, it can be preceded by a character indicating the comparison to be performed.
    474 Permissible characters and the comparisons they specify are as follows:</p>
    475 <dl compact>
    476 <dd></dd>
    477 <dt><tt>=</tt></dt>
    478 <dd>The test shall succeed if the value from the file equals the <i>value</i> field.</dd>
    479 <dt><tt>&lt;</tt></dt>
    480 <dd>The test shall succeed if the value from the file is less than the <i>value</i> field.</dd>
    481 <dt><tt>&gt;</tt></dt>
    482 <dd>The test shall succeed if the value from the file is greater than the <i>value</i> field.</dd>
    483 <dt><tt>&</tt></dt>
    484 <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>
    485 <dt><tt>^</tt></dt>
    486 <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>
    487 <dt><tt>x</tt></dt>
    488 <dd>The test shall succeed if the file is large enough to contain a value of the type specified starting at the offset
    489 specified.</dd>
    490 </dl>
    491 </dd>
    492 <dt><i>message</i></dt>
    493 <dd>The <i>message</i> to be printed if the test succeeds. The <i>message</i> shall be interpreted using the notation for the
    494 <a href="../utilities/printf.html"><i>printf</i></a> formatting specification; see <a href=
    495 "../utilities/printf.html"><i>printf</i></a>. If the <i>value</i> field was a string, then the value from the file shall be the
    496 argument for the <a href="../utilities/printf.html"><i>printf</i></a> formatting specification; otherwise, the value from the file
    497 shall be the argument.</dd>
    498 </dl>
    499 <br></blockquote>
    500 <h4 class="mansect"><a name="tag_20_46_14" id="tag_20_46_14"></a>EXIT STATUS</h4>
    501 <blockquote>
    502 <p>The following exit values shall be returned:</p>
    503 <dl compact>
    504 <dd></dd>
    505 <dt>&nbsp;0</dt>
    506 <dd>Successful completion.</dd>
    507 <dt>&gt;0</dt>
    508 <dd>An error occurred.</dd>
    509 </dl>
    510 </blockquote>
    511 <h4 class="mansect"><a name="tag_20_46_15" id="tag_20_46_15"></a>CONSEQUENCES OF ERRORS</h4>
    512 <blockquote>
    513 <p>Default.</p>
    514 </blockquote>
    515 <hr>
    516 <div class="box"><em>The following sections are informative.</em></div>
    517 <h4 class="mansect"><a name="tag_20_46_16" id="tag_20_46_16"></a>APPLICATION USAGE</h4>
    518 <blockquote>
    519 <p>The <i>file</i> utility can only be required to guess at many of the file types because only exhaustive testing can determine
    520 some types with certainty. For example, binary data on some implementations might match the initial segment of an executable or a
    521 <i>tar</i> archive.</p>
    522 <p class="tent">Note that the table indicates that the output contains the stated string. Systems may add text before or after the
    523 string. For executables, as an example, the machine architecture and various facts about how the file was link-edited may be
    524 included. Note also that on systems that recognize shell script files starting with <tt>"#!"</tt> as executable files, these may be
    525 identified as executable binary files rather than as shell scripts.</p>
    526 </blockquote>
    527 <h4 class="mansect"><a name="tag_20_46_17" id="tag_20_46_17"></a>EXAMPLES</h4>
    528 <blockquote>
    529 <p>Determine whether an argument is a binary executable file:</p>
    530 <pre>
    531 <tt>file -- "$1" | grep -q ':.*executable' &amp;&
    532     printf "%s is executable.\n" "$1"
    533 </tt></pre></blockquote>
    534 <h4 class="mansect"><a name="tag_20_46_18" id="tag_20_46_18"></a>RATIONALE</h4>
    535 <blockquote>
    536 <p>The <b>-f</b> option was omitted because the same effect can (and should) be obtained using the <a href=
    537 "../utilities/xargs.html"><i>xargs</i></a> utility.</p>
    538 <p class="tent">Historical versions of the <i>file</i> utility attempt to identify the following types of files: symbolic link,
    539 directory, character special, block special, socket, <i>tar</i> archive, <i>cpio</i> archive, SCCS archive, archive library, empty,
    540 <a href="../utilities/compress.html"><i>compress</i></a> output, <i>pack</i> output, binary data, C source, FORTRAN source,
    541 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
    542 text, ASCII text, various executables, APL workspace, compiled terminfo entries, and CURSES screen images. Only those types that
    543 are reasonably well specified in POSIX or are directly related to POSIX utilities are listed in the table.</p>
    544 <p class="tent">Historical systems have used a &quot;magic file&quot; named <b>/etc/magic</b> to help identify file types. Because it is
    545 generally useful for users and scripts to be able to identify special file types, the <b>-m</b> flag and a portable format for
    546 user-created magic files has been specified. No requirement is made that an implementation of <i>file</i> use this method of
    547 identifying files, only that users be permitted to add their own classifying tests.</p>
    548 <p class="tent">In addition, three options have been added to historical practice. The <b>-d</b> flag has been added to permit
    549 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
    550 for regular files in shell scripts. The <b>-M</b> flag has been added to permit users to ignore any default system tests.</p>
    551 <p class="tent">The POSIX.1-2024 description of default system tests and the interaction between the <b>-d</b>, <b>-M</b>, and
    552 <b>-m</b> options did not clearly indicate that there were two types of &quot;default system tests&quot;. The &quot;position-sensitive tests&quot;
    553 determine file types by looking for certain string or binary values at specific offsets in the file being examined. These
    554 position-sensitive tests were implemented in historical systems using the magic file described above. Some of these tests are now
    555 built into the <i>file</i> utility itself on some implementations so the output can provide more detail than can be provided by
    556 magic files. For example, a magic file can easily identify a file containing a core image on most implementations, but cannot name
    557 the program file that dropped the core. A magic file could produce output such as:</p>
    558 <pre>
    559 <tt>/home/dwc/core: ELF 32-bit MSB core file SPARC Version 1
    560 </tt></pre>
    561 <p class="tent">but by building the test into the <i>file</i> utility, you could get output such as:</p>
    562 <pre>
    563 <tt>/home/dwc/core: ELF 32-bit MSB core file SPARC Version 1, from 'testprog'
    564 </tt></pre>
    565 <p class="tent">These extended built-in tests are still to be treated as position-sensitive default system tests even if they are
    566 not listed in <b>/etc/magic</b> or any other magic file.</p>
    567 <p class="tent">The context-sensitive default system tests were always built into the <i>file</i> utility. These tests looked for
    568 language constructs in text files trying to identify shell scripts, C, FORTRAN, and other computer language source files, and even
    569 plain text files. With the addition of the <b>-m</b> and <b>-M</b> options the distinction between position-sensitive and
    570 context-sensitive default system tests became important because the order of testing is important. The context-sensitive system
    571 default tests should never be applied before any position-sensitive tests even if the <b>-d</b> option is specified before a
    572 <b>-m</b> option or <b>-M</b> option due to the high probability that the context-sensitive system default tests will incorrectly
    573 identify arbitrary text files as text files before position-sensitive tests specified by the <b>-m</b> or <b>-M</b> option would be
    574 applied to give a more accurate identification.</p>
    575 <p class="tent">Leaving the meaning of <b>-M -</b> and <b>-m -</b> unspecified allows an existing prototype of these options to
    576 continue to work in a backwards-compatible manner. (In that implementation, <b>-M -</b> was roughly equivalent to <b>-d</b> in
    577 POSIX.1-2024.)</p>
    578 <p class="tent">The historical <b>-c</b> option was omitted as not particularly useful to users or portable shell scripts. In
    579 addition, a reasonable implementation of the <i>file</i> utility would report any errors found each time the magic file is
    580 read.</p>
    581 <p class="tent">The historical format of the magic file was the same as that specified by the Rationale in the
    582 ISO&nbsp;POSIX-2:1993 standard for the <i>offset</i>, <i>value</i>, and <i>message</i> fields; however, it used less precise type
    583 fields than the format specified by the current normative text. The new type field values are a superset of the historical
    584 ones.</p>
    585 <p class="tent">The following is an example magic file:</p>
    586 <pre>
    587 <tt>0  short     070707              cpio archive
    588 0  short     0143561             Byte-swapped cpio archive
    589 0  string    070707              ASCII cpio archive
    590 0  long      0177555             Very old archive
    591 0  short     0177545             Old archive
    592 0  short     017437              Old packed data
    593 0  string    \037\036            Packed data
    594 0  string    \377\037            Compacted data
    595 0  string    \037\235            Compressed data
    596 &gt;2 byte&amp;0x80 &gt;0                  Block compressed
    597 &gt;2 byte&amp;0x1f x                   %d bits
    598 0  string    \032\001            Compiled Terminfo Entry
    599 0  short     0433                Curses screen image
    600 0  short     0434                Curses screen image
    601 0  string    &lt;ar&gt;                System V Release 1 archive
    602 0  string    !&lt;arch&gt;\n__.SYMDEF  Archive random library
    603 0  string    !&lt;arch&gt;             Archive
    604 0  string    ARF_BEGARF          PHIGS clear text archive
    605 0  long      0x137A2950          Scalable OpenFont binary
    606 0  long      0x137A2951          Encrypted scalable OpenFont binary
    607 </tt></pre>
    608 <p class="tent">The use of a basic integer data type is intended to allow the implementation to choose a word size commonly used by
    609 applications on that architecture.</p>
    610 <p class="tent">Earlier versions of this standard allowed for implementations with bytes other than eight bits, but this has been
    611 modified in this version.</p>
    612 </blockquote>
    613 <h4 class="mansect"><a name="tag_20_46_19" id="tag_20_46_19"></a>FUTURE DIRECTIONS</h4>
    614 <blockquote>
    615 <p>If this utility is directed to display a pathname that contains any bytes that have the encoded value of a &lt;newline&gt;
    616 character when &lt;newline&gt; is a terminator or separator in the output format being used, implementations are encouraged to
    617 treat this as an error. A future version of this standard may require implementations to treat this as an error.</p>
    618 </blockquote>
    619 <h4 class="mansect"><a name="tag_20_46_20" id="tag_20_46_20"></a>SEE ALSO</h4>
    620 <blockquote>
    621 <p><a href="../utilities/ar.html#"><i>ar</i></a> , <a href="../utilities/ls.html#"><i>ls</i></a> , <a href=
    622 "../utilities/pax.html#"><i>pax</i></a> , <a href="../utilities/printf.html#tag_20_96"><i>printf</i></a></p>
    623 <p class="tent">XBD <a href="../basedefs/V1_chap05.html#tagtcjh_2"><i>Escape Sequences and Associated Actions</i></a> , <a href=
    624 "../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2
    625 Utility Syntax Guidelines</i></a></p>
    626 </blockquote>
    627 <h4 class="mansect"><a name="tag_20_46_21" id="tag_20_46_21"></a>CHANGE HISTORY</h4>
    628 <blockquote>
    629 <p>First released in Issue 4.</p>
    630 </blockquote>
    631 <h4 class="mansect"><a name="tag_20_46_22" id="tag_20_46_22"></a>Issue 6</h4>
    632 <blockquote>
    633 <p>This utility is marked as part of the User Portability Utilities option.</p>
    634 <p class="tent">Options and an EXTENDED DESCRIPTION are added as specified in the IEEE&nbsp;P1003.2b draft standard.</p>
    635 <p class="tent">IEEE PASC Interpretations 1003.2 #192 and #178 are applied.</p>
    636 <p class="tent">IEEE&nbsp;Std&nbsp;1003.1-2001/Cor&nbsp;1-2002, item XCU/TC1/D6/25 is applied, making major changes to address
    637 ambiguities raised in defect reports.</p>
    638 <p class="tent">IEEE&nbsp;Std&nbsp;1003.1-2001/Cor&nbsp;1-2002, item XCU/TC1/D6/26 is applied, making it clear in the OPTIONS
    639 section that the <b>-m</b>, <b>-d</b>, and <b>-M</b> options do not comply with Guideline 11 of the Utility Syntax Guidelines.</p>
    640 <p class="tent">IEEE&nbsp;Std&nbsp;1003.1-2001/Cor&nbsp;2-2004, item XCU/TC2/D6/10 is applied, clarifying the specification
    641 characters.</p>
    642 <p class="tent">IEEE&nbsp;Std&nbsp;1003.1-2001/Cor&nbsp;2-2004, item XCU/TC2/D6/11 is applied, allowing application developers to
    643 create portable magic files that can match characters in strings, and allowing common extensions found in existing
    644 implementations.</p>
    645 <p class="tent">IEEE&nbsp;Std&nbsp;1003.1-2001/Cor&nbsp;2-2004, item XCU/TC2/D6/12 is applied, removing text describing behavior on
    646 systems with bytes consisting of more than eight bits.</p>
    647 </blockquote>
    648 <h4 class="mansect"><a name="tag_20_46_23" id="tag_20_46_23"></a>Issue 7</h4>
    649 <blockquote>
    650 <p>Austin Group Interpretation 1003.1-2001 #092 is applied.</p>
    651 <p class="tent">SD5-XCU-ERN-4 is applied, adding further entries in the Notes column in <a href="#tagtcjh_20">File Utility Output
    652 Strings</a> .</p>
    653 <p class="tent">SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p>
    654 <p class="tent">The <i>file</i> utility is moved from the User Portability Utilities option to the Base. User Portability Utilities
    655 is now an option for interactive utilities.</p>
    656 <p class="tent">The EXAMPLES section is revised to correct an error with the pathname <tt>"$1"</tt>.</p>
    657 </blockquote>
    658 <h4 class="mansect"><a name="tag_20_46_24" id="tag_20_46_24"></a>Issue 8</h4>
    659 <blockquote>
    660 <p>Austin Group Defect 251 is applied, encouraging implementations to report an error if a utility is directed to display a
    661 pathname that contains any bytes that have the encoded value of a &lt;newline&gt; character when &lt;newline&gt; is a terminator or
    662 separator in the output format being used.</p>
    663 <p class="tent">Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p>
    664 <p class="tent">Austin Group Defect 1141 is applied, changing &quot;core file&quot; to &quot;file containing a core image&quot;.</p>
    665 </blockquote>
    666 <div class="box"><em>End of informative text.</em></div>
    667 <hr>
    668 <p>&nbsp;</p>
    669 <a href="#top"><span class="topOfPage">return to top of page</span></a><br>
    670 <hr size="2" noshade>
    671 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br>
    672 POSIX™ is a Trademark of The IEEE.<br>
    673 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br>
    674 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
    675 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a>
    676 ]</font></center>
    677 <hr size="2" noshade>
    678 <div class="NAVHEADER">
    679 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
    680 <tr class="nav">
    681 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/fg.html" accesskey="P">&lt;&lt;&lt;
    682 Previous</a></td>
    683 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
    684 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/find.html" accesskey="N">Next &gt;&gt;&gt;</a></td>
    685 </tr>
    686 </table>
    687 <hr align="left" width="100%"></div>
    688 </body>
    689 </html>