isposix

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

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

tail.html (18512B)


      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>tail</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/tabs.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/talk.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="tail" id="tail"></a> <a name="tag_20_118" id="tag_20_118"></a><!-- tail -->
     28 <h4 class="mansect"><a name="tag_20_118_01" id="tag_20_118_01"></a>NAME</h4>
     29 <blockquote>tail — copy the last part of a file</blockquote>
     30 <h4 class="mansect"><a name="tag_20_118_02" id="tag_20_118_02"></a>SYNOPSIS</h4>
     31 <blockquote class="synopsis">
     32 <p><code><tt>tail</tt> <b>[</b><tt>-f</tt><b>] [</b><tt>-c</tt> <i>number</i><tt>|-n</tt> <i>number</i><b>] [</b><i>file</i><b>]</b>
     33 <tt><br>
     34 <br>
     35 tail -r</tt> <b>[</b><tt>-n</tt> <i>number</i><b>] [</b><i>file</i><b>]</b> <tt><br></tt></code></p>
     36 </blockquote>
     37 <h4 class="mansect"><a name="tag_20_118_03" id="tag_20_118_03"></a>DESCRIPTION</h4>
     38 <blockquote>
     39 <p>The <i>tail</i> utility shall copy its input file to the standard output beginning at a designated place.</p>
     40 <p>Copying shall begin at the point in the file indicated by the <b>-c</b> <i>number</i> or <b>-n</b> <i>number</i> options. The
     41 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
     42 line and byte counts start from 1.</p>
     43 <p>Tails relative to the end of the file may be saved in an internal buffer, and thus may be limited in length. Such a buffer, if
     44 any, shall be no smaller than {LINE_MAX}*10 bytes.</p>
     45 </blockquote>
     46 <h4 class="mansect"><a name="tag_20_118_04" id="tag_20_118_04"></a>OPTIONS</h4>
     47 <blockquote>
     48 <p>The <i>tail</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax
     49 Guidelines</i></a> , except that <tt>'+'</tt> may be recognized as an option delimiter as well as <tt>'-'</tt>.</p>
     50 <p>The following options shall be supported:</p>
     51 <dl compact>
     52 <dd></dd>
     53 <dt><b>-c&nbsp;</b><i>number</i></dt>
     54 <dd>The application shall ensure that the <i>number</i> option-argument is a decimal integer, optionally including a sign. The sign
     55 shall affect the location in the file, measured in bytes, to begin the copying:
     56 <center>
     57 <table border="1" cellpadding="3" align="center">
     58 <tr valign="top">
     59 <th align="center">
     60 <p class="tent"><b>Sign</b></p>
     61 </th>
     62 <th align="center">
     63 <p class="tent"><b>Copying Starts</b></p>
     64 </th>
     65 </tr>
     66 <tr valign="top">
     67 <td align="center">
     68 <p class="tent">+</p>
     69 </td>
     70 <td align="left">
     71 <p class="tent">Relative to the beginning of the file.</p>
     72 </td>
     73 </tr>
     74 <tr valign="top">
     75 <td align="center">
     76 <p class="tent">-</p>
     77 </td>
     78 <td align="left">
     79 <p class="tent">Relative to the end of the file.</p>
     80 </td>
     81 </tr>
     82 <tr valign="top">
     83 <td align="center">
     84 <p class="tent"><i>none</i></p>
     85 </td>
     86 <td align="left">
     87 <p class="tent">Relative to the end of the file.</p>
     88 </td>
     89 </tr>
     90 </table>
     91 </center>
     92 <p class="tent">The application shall ensure that if the sign of the <i>number</i> option-argument is <tt>'+'</tt>, the
     93 <i>number</i> option-argument is a non-zero decimal integer.</p>
     94 <p class="tent">The origin for counting shall be 1; that is, <b>-c</b> +1 represents the first byte of the file, <b>-c</b> -1 the
     95 last.</p>
     96 </dd>
     97 <dt><b>-f</b></dt>
     98 <dd>If the input file is a regular file or if the <i>file</i> operand specifies a FIFO, do not terminate after the last line of the
     99 input file has been copied, but read and copy further bytes from the input file when they become available. If no <i>file</i>
    100 operand is specified and standard input is a pipe or FIFO, the <b>-f</b> option shall be ignored. If the input file is not a FIFO,
    101 pipe, or regular file, it is unspecified whether or not the <b>-f</b> option shall be ignored.</dd>
    102 <dt><b>-n&nbsp;</b><i>number</i></dt>
    103 <dd>If <b>-r</b> is not specified, this option shall be equivalent to <b>-c</b> <i>number</i>, except the starting location in the
    104 file shall be measured in lines instead of bytes. The origin for counting shall be 1; that is, <b>-n</b> +1 represents the first
    105 line of the file, <b>-n</b> -1 the last.
    106 <p class="tent">If <b>-r</b> is specified, <i>number</i> shall specify the number of lines to read (in reverse) from the end of the
    107 input file. The application shall ensure that <i>number</i> does not have a sign.</p>
    108 </dd>
    109 <dt><b>-r</b></dt>
    110 <dd>Copy the lines in reverse order (last line first). If <b>-n</b> is specified, that many lines of the file, starting with the
    111 last line, shall be copied. If <b>-n</b> is not specified, every line of the input file shall be copied.</dd>
    112 </dl>
    113 <p class="tent">If none of the <b>-c</b>, <b>-n</b> or <b>-r</b> options is specified, <b>-n</b> 10 shall be assumed.</p>
    114 </blockquote>
    115 <h4 class="mansect"><a name="tag_20_118_05" id="tag_20_118_05"></a>OPERANDS</h4>
    116 <blockquote>
    117 <p>The following operand shall be supported:</p>
    118 <dl compact>
    119 <dd></dd>
    120 <dt><i>file</i></dt>
    121 <dd>A pathname of an input file. If no <i>file</i> operand is specified, the standard input shall be used.</dd>
    122 </dl>
    123 </blockquote>
    124 <h4 class="mansect"><a name="tag_20_118_06" id="tag_20_118_06"></a>STDIN</h4>
    125 <blockquote>
    126 <p>The standard input shall be used if no <i>file</i> operand is specified, and shall be used if the <i>file</i> operand is
    127 <tt>'-'</tt> and the implementation treats the <tt>'-'</tt> as meaning standard input. Otherwise, the standard input shall not be
    128 used. See the INPUT FILES section.</p>
    129 </blockquote>
    130 <h4 class="mansect"><a name="tag_20_118_07" id="tag_20_118_07"></a>INPUT FILES</h4>
    131 <blockquote>
    132 <p>If the <b>-c</b> option is specified, the input file can contain arbitrary data; otherwise, the input file shall be a text
    133 file.</p>
    134 </blockquote>
    135 <h4 class="mansect"><a name="tag_20_118_08" id="tag_20_118_08"></a>ENVIRONMENT VARIABLES</h4>
    136 <blockquote>
    137 <p>The following environment variables shall affect the execution of <i>tail</i>:</p>
    138 <dl compact>
    139 <dd></dd>
    140 <dt><i>LANG</i></dt>
    141 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href=
    142 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization
    143 variables used to determine the values of locale categories.)</dd>
    144 <dt><i>LC_ALL</i></dt>
    145 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
    146 <dt><i>LC_CTYPE</i></dt>
    147 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
    148 opposed to multi-byte characters in arguments and input files).</dd>
    149 <dt><i>LC_MESSAGES</i></dt>
    150 <dd><br>
    151 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd>
    152 <dt><i>NLSPATH</i></dt>
    153 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
    154 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border=
    155 "0"></dd>
    156 </dl>
    157 </blockquote>
    158 <h4 class="mansect"><a name="tag_20_118_09" id="tag_20_118_09"></a>ASYNCHRONOUS EVENTS</h4>
    159 <blockquote>
    160 <p>Default.</p>
    161 </blockquote>
    162 <h4 class="mansect"><a name="tag_20_118_10" id="tag_20_118_10"></a>STDOUT</h4>
    163 <blockquote>
    164 <p>The designated portion of the input file shall be written to standard output.</p>
    165 </blockquote>
    166 <h4 class="mansect"><a name="tag_20_118_11" id="tag_20_118_11"></a>STDERR</h4>
    167 <blockquote>
    168 <p>The standard error shall be used only for diagnostic messages.</p>
    169 </blockquote>
    170 <h4 class="mansect"><a name="tag_20_118_12" id="tag_20_118_12"></a>OUTPUT FILES</h4>
    171 <blockquote>
    172 <p>None.</p>
    173 </blockquote>
    174 <h4 class="mansect"><a name="tag_20_118_13" id="tag_20_118_13"></a>EXTENDED DESCRIPTION</h4>
    175 <blockquote>
    176 <p>None.</p>
    177 </blockquote>
    178 <h4 class="mansect"><a name="tag_20_118_14" id="tag_20_118_14"></a>EXIT STATUS</h4>
    179 <blockquote>
    180 <p>The following exit values shall be returned:</p>
    181 <dl compact>
    182 <dd></dd>
    183 <dt>&nbsp;0</dt>
    184 <dd>Successful completion.</dd>
    185 <dt>&gt;0</dt>
    186 <dd>An error occurred.</dd>
    187 </dl>
    188 </blockquote>
    189 <h4 class="mansect"><a name="tag_20_118_15" id="tag_20_118_15"></a>CONSEQUENCES OF ERRORS</h4>
    190 <blockquote>
    191 <p>Default.</p>
    192 </blockquote>
    193 <hr>
    194 <div class="box"><em>The following sections are informative.</em></div>
    195 <h4 class="mansect"><a name="tag_20_118_16" id="tag_20_118_16"></a>APPLICATION USAGE</h4>
    196 <blockquote>
    197 <p>The <b>-c</b> option should be used with caution when the input is a text file containing multi-byte characters; it may produce
    198 output that does not start on a character boundary.</p>
    199 <p class="tent">Although the input file to <i>tail</i> can be any type, the results might not be what would be expected on some
    200 character special device files or on file types not described by the System Interfaces volume of POSIX.1-2024. Since this volume of
    201 POSIX.1-2024 does not specify the block size used when doing input, <i>tail</i> need not read all of the data from devices that
    202 only perform block transfers.</p>
    203 <p class="tent">When using <i>tail</i> to process pathnames, and the <b>-c</b> option is not specified, it is recommended that
    204 LC_ALL, or at least LC_CTYPE and LC_COLLATE, are set to POSIX or C in the environment, since pathnames can contain byte sequences
    205 that do not form valid characters in some locales, in which case the utility's behavior would be undefined. In the POSIX locale
    206 each byte is a valid single-byte character, and therefore this problem is avoided.</p>
    207 </blockquote>
    208 <h4 class="mansect"><a name="tag_20_118_17" id="tag_20_118_17"></a>EXAMPLES</h4>
    209 <blockquote>
    210 <p>The <b>-f</b> option can be used to monitor the growth of a file that is being written by some other process. For example, the
    211 command:</p>
    212 <pre>
    213 <tt>tail -f fred
    214 </tt></pre>
    215 <p class="tent">prints the last ten lines of the file <b>fred</b>, followed by any lines that are appended to <b>fred</b> between
    216 the time <i>tail</i> is initiated and killed. As another example, the command:</p>
    217 <pre>
    218 <tt>tail -f -c 15 fred
    219 </tt></pre>
    220 <p class="tent">prints the last 15 bytes of the file <b>fred</b>, followed by any bytes that are appended to <b>fred</b> between
    221 the time <i>tail</i> is initiated and killed.</p>
    222 </blockquote>
    223 <h4 class="mansect"><a name="tag_20_118_18" id="tag_20_118_18"></a>RATIONALE</h4>
    224 <blockquote>
    225 <p>This version of <i>tail</i> was created to allow conformance to the Utility Syntax Guidelines. The historical <b>-b</b> option
    226 was omitted because of the general non-portability of block-sized units of text. The <b>-c</b> option historically meant
    227 &quot;characters&quot;, but this volume of POSIX.1-2024 indicates that it means &quot;bytes&quot;. This was selected to allow reasonable
    228 implementations when multi-byte characters are possible; it was not named <b>-b</b> to avoid confusion with the historical
    229 <b>-b</b>.</p>
    230 <p class="tent">The origin of counting both lines and bytes is 1, matching all widespread historical implementations. Hence
    231 <i>tail</i> <b>-n</b> +0 is not conforming usage because it attempts to output line zero; but note that <i>tail</i> <b>-n</b> 0
    232 does conform, and outputs nothing.</p>
    233 <p class="tent">Earlier versions of this standard allowed the following forms in the SYNOPSIS:</p>
    234 <pre>
    235 <tt>tail -</tt><b>[</b><tt>number</tt><b>][</b><tt>b|c|l</tt><b>][</b><tt>f</tt><b>] [</b><i>file</i><b>]</b><tt>
    236 tail +</tt><b>[</b><tt>number</tt><b>][</b><tt>b|c|l</tt><b>][</b><tt>f</tt><b>] [</b><i>file</i><b>]</b><tt>
    237 </tt></pre>
    238 <p class="tent">These forms are no longer specified by POSIX.1-2024, but may be present in some implementations.</p>
    239 <p class="tent">The restriction on the internal buffer is a compromise between the historical System V implementation of 4096 bytes
    240 and the BSD 32768 bytes.</p>
    241 <p class="tent">The <b>-f</b> option has been implemented as a loop that sleeps for 1 second and copies any bytes that are
    242 available. This is sufficient, but if more efficient methods of determining when new data are available are developed,
    243 implementations are encouraged to use them.</p>
    244 <p class="tent">Historical documentation indicates that <i>tail</i> ignores the <b>-f</b> option if the input file is a pipe (pipe
    245 and FIFO on systems that support FIFOs). On BSD-based systems, this has been true; on System V-based systems, this was true when
    246 input was taken from standard input, but it did not ignore the <b>-f</b> flag if a FIFO was named as the <i>file</i> operand. Since
    247 the <b>-f</b> option is not useful on pipes and all historical implementations ignore <b>-f</b> if no <i>file</i> operand is
    248 specified and standard input is a pipe, this volume of POSIX.1-2024 requires this behavior. However, since the <b>-f</b> option is
    249 useful on a FIFO, this volume of POSIX.1-2024 also requires that if a FIFO is named, the <b>-f</b> option shall not be ignored.
    250 Earlier versions of this standard did not state any requirement for the case where no <i>file</i> operand is specified and standard
    251 input is a FIFO. The standard has been updated to reflect current practice which is to treat this case the same as a pipe on
    252 standard input. Although historical behavior does not ignore the <b>-f</b> option for other file types, this is unspecified so that
    253 implementations are allowed to ignore the <b>-f</b> option if it is known that the file cannot be extended.</p>
    254 <p class="tent">The functionality made available by <i>tail</i> <b>-r</b> has been historically provided on some systems by a
    255 separate utility (<i>tac</i>), although <i>tac</i> traditionally lacked support for <b>-n</b> to limit the output. While both
    256 <tt>tail -n$n | tac</tt> and <tt>tac | head -n$n</tt> can be used to output a fixed length of reversed line output, the standard
    257 developers decided that it was preferable to have a single utility <tt>tail -r -n$n</tt> for the same purpose. Furthermore, in
    258 deciding whether to standardize <i>tac</i> rather than <i>tail</i> <b>-r</b>, it was determined that more implementations that have
    259 achieved POSIX certification had already implemented <i>tail</i> <b>-r</b> as an extension.</p>
    260 </blockquote>
    261 <h4 class="mansect"><a name="tag_20_118_19" id="tag_20_118_19"></a>FUTURE DIRECTIONS</h4>
    262 <blockquote>
    263 <p>None.</p>
    264 </blockquote>
    265 <h4 class="mansect"><a name="tag_20_118_20" id="tag_20_118_20"></a>SEE ALSO</h4>
    266 <blockquote>
    267 <p><a href="../utilities/head.html#"><i>head</i></a></p>
    268 <p class="tent">XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href=
    269 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p>
    270 </blockquote>
    271 <h4 class="mansect"><a name="tag_20_118_21" id="tag_20_118_21"></a>CHANGE HISTORY</h4>
    272 <blockquote>
    273 <p>First released in Issue 2.</p>
    274 </blockquote>
    275 <h4 class="mansect"><a name="tag_20_118_22" id="tag_20_118_22"></a>Issue 6</h4>
    276 <blockquote>
    277 <p>The obsolescent SYNOPSIS lines and associated text are removed.</p>
    278 <p class="tent">The normative text is reworded to avoid use of the term &quot;must&quot; for application requirements.</p>
    279 </blockquote>
    280 <h4 class="mansect"><a name="tag_20_118_23" id="tag_20_118_23"></a>Issue 7</h4>
    281 <blockquote>
    282 <p>Austin Group Interpretation 1003.1-2001 #027 is applied, clarifying that <tt>'+'</tt> may be recognized as an option delimiter
    283 in the OPTIONS section.</p>
    284 <p class="tent">Austin Group Interpretation 1003.1-2001 #092 is applied.</p>
    285 <p class="tent">Austin Group Interpretation 1003.1-2001 #100 is applied, adding the requirement on applications that if the sign of
    286 the option-argument <i>number</i> is <tt>'+'</tt>, the <i>number</i> option-argument is a non-zero decimal integer.</p>
    287 <p class="tent">SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p>
    288 <p class="tent">SD5-XCU-ERN-114 is applied, updating the OPTIONS section (the <b>-f</b> option).</p>
    289 <p class="tent">SD5-XCU-ERN-149 is applied.</p>
    290 <p class="tent">POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0190 [663] is applied.</p>
    291 </blockquote>
    292 <h4 class="mansect"><a name="tag_20_118_24" id="tag_20_118_24"></a>Issue 8</h4>
    293 <blockquote>
    294 <p>Austin Group Defect 877 is applied, adding the <b>-r</b> option.</p>
    295 <p class="tent">Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p>
    296 </blockquote>
    297 <div class="box"><em>End of informative text.</em></div>
    298 <hr>
    299 <p>&nbsp;</p>
    300 <a href="#top"><span class="topOfPage">return to top of page</span></a><br>
    301 <hr size="2" noshade>
    302 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br>
    303 POSIX™ is a Trademark of The IEEE.<br>
    304 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br>
    305 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
    306 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a>
    307 ]</font></center>
    308 <hr size="2" noshade>
    309 <div class="NAVHEADER">
    310 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
    311 <tr class="nav">
    312 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/tabs.html" accesskey="P">&lt;&lt;&lt;
    313 Previous</a></td>
    314 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
    315 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/talk.html" accesskey="N">Next &gt;&gt;&gt;</a></td>
    316 </tr>
    317 </table>
    318 <hr align="left" width="100%"></div>
    319 </body>
    320 </html>