isposix

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

git clone git://bebou.netlib.re/isposix

Log | Files | Refs | README |

head.html (13728B)


      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>head</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/hash.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/iconv.html" accesskey="N">Next
     19 &gt;&gt;&gt;</a></td>
     20 </tr>
     21 </table>
     22 <hr align="left" width="100%"></div>
     23 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3">
     24 <center><font size="2">The Open Group Base Specifications Issue 8<br>
     25 IEEE Std 1003.1-2024<br>
     26 Copyright © 2001-2024 The IEEE and The Open Group</font></center>
     27 <hr size="2" noshade>
     28 <a name="top" id="top"></a> <a name="head" id="head"></a> <a name="tag_20_57" id="tag_20_57"></a><!-- head -->
     29 <h4 class="mansect"><a name="tag_20_57_01" id="tag_20_57_01"></a>NAME</h4>
     30 <blockquote>head — copy the first part of files</blockquote>
     31 <h4 class="mansect"><a name="tag_20_57_02" id="tag_20_57_02"></a>SYNOPSIS</h4>
     32 <blockquote class="synopsis">
     33 <p><code><tt>head</tt> <b>[</b><tt>-c</tt> <i>number</i><tt>|-n</tt> <i>number</i><b>] [</b><i>file</i><tt>...</tt><b>]</b></code></p>
     34 </blockquote>
     35 <h4 class="mansect"><a name="tag_20_57_03" id="tag_20_57_03"></a>DESCRIPTION</h4>
     36 <blockquote>
     37 <p>The <i>head</i> utility shall copy its input files to the standard output, ending the output for each file at a designated
     38 point.</p>
     39 <p>Copying shall end at the point in the file indicated by the <b>-c</b> <i>number</i> or <b>-n</b> <i>number</i> options. The
     40 option-argument <i>number</i> shall be counted in units of lines or bytes, according to the options <b>-n</b> and <b>-c</b>. Both
     41 line and byte counts start from 1.</p>
     42 </blockquote>
     43 <h4 class="mansect"><a name="tag_20_57_04" id="tag_20_57_04"></a>OPTIONS</h4>
     44 <blockquote>
     45 <p>The <i>head</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax
     46 Guidelines</i></a> .</p>
     47 <p>The following options shall be supported:</p>
     48 <dl compact>
     49 <dd></dd>
     50 <dt><b>-c&nbsp;</b><i>number</i></dt>
     51 <dd>The first <i>number</i> bytes of each input file shall be copied to standard output. The application shall ensure that the
     52 <i>number</i> option-argument is a positive decimal integer.</dd>
     53 <dt><b>-n&nbsp;</b><i>number</i></dt>
     54 <dd>This option shall be equivalent to <b>-c</b> <i>number</i>, except that the ending location in the file shall be measured in
     55 lines instead of bytes.</dd>
     56 </dl>
     57 <p>When a file contains less than <i>number</i> bytes or lines, it shall be copied to standard output in its entirety. This shall
     58 not be an error.</p>
     59 <p>If no options are specified, <i>head</i> shall act as if <b>-n 10</b> had been specified.</p>
     60 </blockquote>
     61 <h4 class="mansect"><a name="tag_20_57_05" id="tag_20_57_05"></a>OPERANDS</h4>
     62 <blockquote>
     63 <p>The following operand shall be supported:</p>
     64 <dl compact>
     65 <dd></dd>
     66 <dt><i>file</i></dt>
     67 <dd>A pathname of an input file. If no <i>file</i> operands are specified, the standard input shall be used.</dd>
     68 </dl>
     69 </blockquote>
     70 <h4 class="mansect"><a name="tag_20_57_06" id="tag_20_57_06"></a>STDIN</h4>
     71 <blockquote>
     72 <p>The standard input shall be used if no <i>file</i> operands are specified, and shall be used if a <i>file</i> operand is
     73 <tt>'-'</tt> and the implementation treats the <tt>'-'</tt> as meaning standard input. Otherwise, the standard input shall not be
     74 used. See the INPUT FILES section.</p>
     75 </blockquote>
     76 <h4 class="mansect"><a name="tag_20_57_07" id="tag_20_57_07"></a>INPUT FILES</h4>
     77 <blockquote>
     78 <p>If the <b>-c</b> option is specified, the input files can contain arbitrary data; otherwise, the input files shall be text
     79 files, but the line length shall not be restricted to {LINE_MAX} bytes.</p>
     80 </blockquote>
     81 <h4 class="mansect"><a name="tag_20_57_08" id="tag_20_57_08"></a>ENVIRONMENT VARIABLES</h4>
     82 <blockquote>
     83 <p>The following environment variables shall affect the execution of <i>head</i>:</p>
     84 <dl compact>
     85 <dd></dd>
     86 <dt><i>LANG</i></dt>
     87 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href=
     88 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization
     89 variables used to determine the values of locale categories.)</dd>
     90 <dt><i>LC_ALL</i></dt>
     91 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
     92 <dt><i>LC_CTYPE</i></dt>
     93 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
     94 opposed to multi-byte characters in arguments and input files).</dd>
     95 <dt><i>LC_MESSAGES</i></dt>
     96 <dd><br>
     97 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd>
     98 <dt><i>NLSPATH</i></dt>
     99 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
    100 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border=
    101 "0"></dd>
    102 </dl>
    103 </blockquote>
    104 <h4 class="mansect"><a name="tag_20_57_09" id="tag_20_57_09"></a>ASYNCHRONOUS EVENTS</h4>
    105 <blockquote>
    106 <p>Default.</p>
    107 </blockquote>
    108 <h4 class="mansect"><a name="tag_20_57_10" id="tag_20_57_10"></a>STDOUT</h4>
    109 <blockquote>
    110 <p>The standard output shall contain designated portions of the input files.</p>
    111 <p>If multiple <i>file</i> operands are specified, <i>head</i> shall precede the output for each with the header:</p>
    112 <pre>
    113 <tt>"\n==&gt; %s &lt;==\n", &lt;</tt><i>pathname</i><tt>&gt;
    114 </tt></pre>
    115 <p>except that the first header written shall not include the initial &lt;newline&gt;.</p>
    116 </blockquote>
    117 <h4 class="mansect"><a name="tag_20_57_11" id="tag_20_57_11"></a>STDERR</h4>
    118 <blockquote>
    119 <p>The standard error shall be used only for diagnostic messages.</p>
    120 </blockquote>
    121 <h4 class="mansect"><a name="tag_20_57_12" id="tag_20_57_12"></a>OUTPUT FILES</h4>
    122 <blockquote>
    123 <p>None.</p>
    124 </blockquote>
    125 <h4 class="mansect"><a name="tag_20_57_13" id="tag_20_57_13"></a>EXTENDED DESCRIPTION</h4>
    126 <blockquote>
    127 <p>None.</p>
    128 </blockquote>
    129 <h4 class="mansect"><a name="tag_20_57_14" id="tag_20_57_14"></a>EXIT STATUS</h4>
    130 <blockquote>
    131 <p>The following exit values shall be returned:</p>
    132 <dl compact>
    133 <dd></dd>
    134 <dt>&nbsp;0</dt>
    135 <dd>Successful completion.</dd>
    136 <dt>&gt;0</dt>
    137 <dd>An error occurred.</dd>
    138 </dl>
    139 </blockquote>
    140 <h4 class="mansect"><a name="tag_20_57_15" id="tag_20_57_15"></a>CONSEQUENCES OF ERRORS</h4>
    141 <blockquote>
    142 <p>Default.</p>
    143 </blockquote>
    144 <hr>
    145 <div class="box"><em>The following sections are informative.</em></div>
    146 <h4 class="mansect"><a name="tag_20_57_16" id="tag_20_57_16"></a>APPLICATION USAGE</h4>
    147 <blockquote>
    148 <p>When using <i>head</i> to process pathnames, it is recommended that LC_ALL, or at least LC_CTYPE and LC_COLLATE, are set to
    149 POSIX or C in the environment, since pathnames can contain byte sequences that do not form valid characters in some locales, in
    150 which case the utility's behavior would be undefined. In the POSIX locale each byte is a valid single-byte character, and therefore
    151 this problem is avoided.</p>
    152 </blockquote>
    153 <h4 class="mansect"><a name="tag_20_57_17" id="tag_20_57_17"></a>EXAMPLES</h4>
    154 <blockquote>
    155 <p>To write the first ten lines of all files (except those with a leading period) in the directory:</p>
    156 <pre>
    157 <tt>head -- *
    158 </tt></pre></blockquote>
    159 <h4 class="mansect"><a name="tag_20_57_18" id="tag_20_57_18"></a>RATIONALE</h4>
    160 <blockquote>
    161 <p>Although it is possible to simulate <i>head</i> with <a href="../utilities/sed.html"><i>sed</i></a> 10q for a single file, the
    162 standard developers decided that the popularity of <i>head</i> on historical BSD systems warranted its inclusion alongside <a href=
    163 "../utilities/tail.html"><i>tail</i></a>.</p>
    164 <p>POSIX.1-2024 version of <i>head</i> follows the Utility Syntax Guidelines. The <b>-n</b> option was added to this new interface
    165 so that <i>head</i> and <a href="../utilities/tail.html"><i>tail</i></a> would be more logically related. Earlier versions of this
    166 standard allowed a <b>-number</b> option. This form is no longer specified by POSIX.1-2024 but may be present in some
    167 implementations.</p>
    168 <p>The <i>head</i> and <a href="../utilities/tail.html"><i>tail</i></a> utilities have not historically been symmetric. For
    169 example, this standard only requires <a href="../utilities/tail.html"><i>tail</i></a> to support at most one file operand, while
    170 <i>head</i> must operate on multiple files. Conversely, this standard requires <a href="../utilities/tail.html"><i>tail</i></a> to
    171 be able to start at a position relative to the start of a file, but <i>head</i> need not support stopping at a position relative to
    172 the end of the file. Implementations may choose to make <i>head</i> and <a href="../utilities/tail.html"><i>tail</i></a> symmetric
    173 as an extension, but applications should not rely on this.</p>
    174 <p>Older implementations of <i>head</i> did not support <b>-c</b> <i>number</i>, but emulating this via <tt>dd ibs=1
    175 count=number</tt> is much less efficient and emulating via <tt>dd obs=pipe_buf | dd ibs=size count=number_of_blocks</tt> is
    176 cumbersome, somewhat less efficient, and can only be used if the number of bytes to be copied is a multiple of a suitable block
    177 size less than or equal to {PIPE_BUF}.</p>
    178 </blockquote>
    179 <h4 class="mansect"><a name="tag_20_57_19" id="tag_20_57_19"></a>FUTURE DIRECTIONS</h4>
    180 <blockquote>
    181 <p>If this utility is directed to display a pathname that contains any bytes that have the encoded value of a &lt;newline&gt;
    182 character when &lt;newline&gt; is a terminator or separator in the output format being used, implementations are encouraged to
    183 treat this as an error. A future version of this standard may require implementations to treat this as an error.</p>
    184 </blockquote>
    185 <h4 class="mansect"><a name="tag_20_57_20" id="tag_20_57_20"></a>SEE ALSO</h4>
    186 <blockquote>
    187 <p><a href="../utilities/dd.html#"><i>dd</i></a> , <a href="../utilities/sed.html#"><i>sed</i></a> , <a href=
    188 "../utilities/tail.html#"><i>tail</i></a></p>
    189 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href=
    190 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p>
    191 </blockquote>
    192 <h4 class="mansect"><a name="tag_20_57_21" id="tag_20_57_21"></a>CHANGE HISTORY</h4>
    193 <blockquote>
    194 <p>First released in Issue 4.</p>
    195 </blockquote>
    196 <h4 class="mansect"><a name="tag_20_57_22" id="tag_20_57_22"></a>Issue 6</h4>
    197 <blockquote>
    198 <p>The obsolescent <b>-number</b> form is removed.</p>
    199 <p>The normative text is reworded to avoid use of the term &quot;must&quot; for application requirements.</p>
    200 <p>The DESCRIPTION is updated to clarify that when a file contains less than the number of lines requested, the entire file is
    201 copied to standard output.</p>
    202 </blockquote>
    203 <h4 class="mansect"><a name="tag_20_57_23" id="tag_20_57_23"></a>Issue 7</h4>
    204 <blockquote>
    205 <p>Austin Group Interpretations 1003.1-2001 #027 and #092 are applied.</p>
    206 <p>SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p>
    207 <p>The APPLICATION USAGE section is removed and the EXAMPLES section is corrected.</p>
    208 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0107 [663] is applied.</p>
    209 </blockquote>
    210 <h4 class="mansect"><a name="tag_20_57_24" id="tag_20_57_24"></a>Issue 8</h4>
    211 <blockquote>
    212 <p>Austin Group Defect 251 is applied, encouraging implementations to report an error if a utility is directed to display a
    213 pathname that contains any bytes that have the encoded value of a &lt;newline&gt; character when &lt;newline&gt; is a terminator or
    214 separator in the output format being used.</p>
    215 <p>Austin Group Defect 407 is applied, adding the <b>-c</b> <i>number</i> option.</p>
    216 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p>
    217 </blockquote>
    218 <div class="box"><em>End of informative text.</em></div>
    219 <hr>
    220 <p>&nbsp;</p>
    221 <a href="#top"><span class="topOfPage">return to top of page</span></a><br>
    222 <hr size="2" noshade>
    223 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br>
    224 POSIX™ is a Trademark of The IEEE.<br>
    225 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br>
    226 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
    227 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a>
    228 ]</font></center>
    229 <hr size="2" noshade>
    230 <div class="NAVHEADER">
    231 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
    232 <tr class="nav">
    233 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/hash.html" accesskey="P">&lt;&lt;&lt;
    234 Previous</a></td>
    235 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
    236 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/iconv.html" accesskey="N">Next
    237 &gt;&gt;&gt;</a></td>
    238 </tr>
    239 </table>
    240 <hr align="left" width="100%"></div>
    241 </body>
    242 </html>