Un outil pour savoir si une commande est posix - retour accueil
git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |
ln.html (20010B)
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>ln</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/link.html" accesskey="P"><<< 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/locale.html" accesskey="N">Next 19 >>></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="ln" id="ln"></a> <a name="tag_20_67" id="tag_20_67"></a><!-- ln --> 29 <h4 class="mansect"><a name="tag_20_67_01" id="tag_20_67_01"></a>NAME</h4> 30 <blockquote>ln — link files</blockquote> 31 <h4 class="mansect"><a name="tag_20_67_02" id="tag_20_67_02"></a>SYNOPSIS</h4> 32 <blockquote class="synopsis"> 33 <p><code><tt>ln</tt> <b>[</b><tt>-fs</tt><b>] [</b><tt>-L|-P</tt><b>]</b> <i>source_file target_file</i> <tt><br> 34 <br> 35 ln</tt> <b>[</b><tt>-fs</tt><b>] [</b><tt>-L|-P</tt><b>]</b> <i>source_file</i><tt>...</tt> <i>target_dir</i> <tt><br></tt></code></p> 36 </blockquote> 37 <h4 class="mansect"><a name="tag_20_67_03" id="tag_20_67_03"></a>DESCRIPTION</h4> 38 <blockquote> 39 <p>In the first synopsis form, the <i>ln</i> utility shall create a new directory entry at the destination path specified by the 40 <i>target_file</i> operand. If the <b>-s</b> option is specified, a symbolic link shall be created with the contents specified by 41 the <i>source_file</i> operand (which need not name an existing file); otherwise, a hard link shall be created to the file named by 42 the <i>source_file</i> operand. This first synopsis form shall be assumed when the final operand does not name an existing 43 directory; if more than two operands are specified and the final is not an existing directory, an error shall result.</p> 44 <p>In the second synopsis form, the <i>ln</i> utility shall create a new directory entry for each <i>source_file</i> operand, at a 45 destination path in the existing directory named by <i>target_dir</i>. If the <b>-s</b> option is specified, a symbolic link shall 46 be created with the contents specified by each <i>source_file</i> operand (which need not name an existing file); otherwise, a hard 47 link shall be created to each file named by a <i>source_file</i> operand.</p> 48 <p>If the last operand specifies an existing file of a type not specified by the System Interfaces volume of POSIX.1-2024, the 49 behavior is implementation-defined.</p> 50 <p>The corresponding destination path for each <i>source_file</i> shall be the concatenation of the target directory pathname, a 51 <slash> character if the target directory pathname did not end in a <slash>, and the last pathname component of the 52 <i>source_file</i>. The second synopsis form shall be assumed when the final operand names an existing directory.</p> 53 <p>For each <i>source_file</i>:</p> 54 <ol> 55 <li> 56 <p>If the destination path exists and was created by a previous step, it is unspecified whether <i>ln</i> writes a diagnostic 57 message to standard error, does nothing more with the current <i>source_file</i>, and goes on to any remaining <i>source_file</i>s; 58 or continues processing the current <i>source_file</i>. If the destination path exists:</p> 59 <ol type="a"> 60 <li> 61 <p>If the <b>-f</b> option is not specified, <i>ln</i> shall write a diagnostic message to standard error, do nothing more with the 62 current <i>source_file</i>, and go on to any remaining <i>source_file</i>s.</p> 63 </li> 64 <li> 65 <p>If the destination path names the same directory entry as the current <i>source_file</i> <i>ln</i> shall write a diagnostic 66 message to standard error, do nothing more with the current <i>source_file</i>, and go on to any remaining 67 <i>source_file</i>s<i>.</i></p> 68 </li> 69 <li> 70 <p>Actions shall be performed equivalent to the <a href="../functions/unlink.html"><i>unlink</i>()</a> function defined in the 71 System Interfaces volume of POSIX.1-2024, called using the destination path as the <i>path</i> argument. If this fails for any 72 reason, <i>ln</i> shall write a diagnostic message to standard error, do nothing more with the current <i>source_file</i>, and go 73 on to any remaining <i>source_file</i>s.</p> 74 </li> 75 </ol> 76 </li> 77 <li> 78 <p>If the <b>-s</b> option is specified, actions shall be performed equivalent to the <a href= 79 "../functions/symlink.html"><i>symlink</i>()</a> function with <i>source_file</i> as the <i>path1</i> argument and the destination 80 path as the <i>path2</i> argument. The <i>ln</i> utility shall do nothing more with <i>source_file</i> and shall go on to any 81 remaining files.</p> 82 </li> 83 <li> 84 <p>If <i>source_file</i> is a symbolic link:</p> 85 <ol type="a"> 86 <li> 87 <p>If the <b>-P</b> option is in effect, actions shall be performed equivalent to the <a href= 88 "../functions/linkat.html"><i>linkat</i>()</a> function with <i>source_file</i> as the <i>path1</i> argument, the destination path 89 as the <i>path2</i> argument, AT_FDCWD as the <i>fd1</i> and <i>fd2</i> arguments, and zero as the <i>flag</i> argument.</p> 90 </li> 91 <li> 92 <p>If the <b>-L</b> option is in effect, actions shall be performed equivalent to the <a href= 93 "../functions/linkat.html"><i>linkat</i>()</a> function with <i>source_file</i> as the <i>path1</i> argument, the destination path 94 as the <i>path2</i> argument, AT_FDCWD as the <i>fd1</i> and <i>fd2</i> arguments, and AT_SYMLINK_FOLLOW as the <i>flag</i> 95 argument.</p> 96 </li> 97 </ol> 98 <p>The <i>ln</i> utility shall do nothing more with <i>source_file</i> and shall go on to any remaining files.</p> 99 </li> 100 <li> 101 <p>Actions shall be performed equivalent to the <a href="../functions/link.html"><i>link</i>()</a> function defined in the System 102 Interfaces volume of POSIX.1-2024 using <i>source_file</i> as the <i>path1</i> argument, and the destination path as the 103 <i>path2</i> argument.</p> 104 </li> 105 </ol> 106 </blockquote> 107 <h4 class="mansect"><a name="tag_20_67_04" id="tag_20_67_04"></a>OPTIONS</h4> 108 <blockquote> 109 <p>The <i>ln</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax 110 Guidelines</i></a> .</p> 111 <p>The following options shall be supported:</p> 112 <dl compact> 113 <dd></dd> 114 <dt><b>-f</b></dt> 115 <dd>Force existing destination pathnames to be removed to allow the link.</dd> 116 <dt><b>-L</b></dt> 117 <dd>For each <i>source_file</i> operand that names a file of type symbolic link, create a hard link to the file referenced by the 118 symbolic link.</dd> 119 <dt><b>-P</b></dt> 120 <dd>For each <i>source_file</i> operand that names a file of type symbolic link, create a hard link to the symbolic link 121 itself.</dd> 122 <dt><b>-s</b></dt> 123 <dd>Create symbolic links instead of hard links. If the <b>-s</b> option is specified, the <b>-L</b> and <b>-P</b> options shall be 124 silently ignored.</dd> 125 </dl> 126 <p>Specifying more than one of the mutually-exclusive options <b>-L</b> and <b>-P</b> shall not be considered an error. The last 127 option specified shall determine the behavior of the utility (unless the <b>-s</b> option causes it to be ignored).</p> 128 <p>If the <b>-s</b> option is not specified and neither a <b>-L</b> nor a <b>-P</b> option is specified, it is 129 implementation-defined which of the <b>-L</b> and <b>-P</b> options is used as the default.</p> 130 </blockquote> 131 <h4 class="mansect"><a name="tag_20_67_05" id="tag_20_67_05"></a>OPERANDS</h4> 132 <blockquote> 133 <p>The following operands shall be supported:</p> 134 <dl compact> 135 <dd></dd> 136 <dt><i>source_file</i></dt> 137 <dd>A pathname of a file to be linked. If the <b>-s</b> option is specified, no restrictions on the type of file or on its 138 existence shall be made. If the <b>-s</b> option is not specified, whether a directory can be linked is 139 implementation-defined.</dd> 140 <dt><i>target_file</i></dt> 141 <dd>The pathname of the new directory entry to be created.</dd> 142 <dt><i>target_dir</i></dt> 143 <dd>A pathname of an existing directory in which the new directory entries are created.</dd> 144 </dl> 145 </blockquote> 146 <h4 class="mansect"><a name="tag_20_67_06" id="tag_20_67_06"></a>STDIN</h4> 147 <blockquote> 148 <p>Not used.</p> 149 </blockquote> 150 <h4 class="mansect"><a name="tag_20_67_07" id="tag_20_67_07"></a>INPUT FILES</h4> 151 <blockquote> 152 <p>None.</p> 153 </blockquote> 154 <h4 class="mansect"><a name="tag_20_67_08" id="tag_20_67_08"></a>ENVIRONMENT VARIABLES</h4> 155 <blockquote> 156 <p>The following environment variables shall affect the execution of <i>ln</i>:</p> 157 <dl compact> 158 <dd></dd> 159 <dt><i>LANG</i></dt> 160 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href= 161 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization 162 variables used to determine the values of locale categories.)</dd> 163 <dt><i>LC_ALL</i></dt> 164 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd> 165 <dt><i>LC_CTYPE</i></dt> 166 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as 167 opposed to multi-byte characters in arguments).</dd> 168 <dt><i>LC_MESSAGES</i></dt> 169 <dd><br> 170 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd> 171 <dt><i>NLSPATH</i></dt> 172 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 173 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border= 174 "0"></dd> 175 </dl> 176 </blockquote> 177 <h4 class="mansect"><a name="tag_20_67_09" id="tag_20_67_09"></a>ASYNCHRONOUS EVENTS</h4> 178 <blockquote> 179 <p>Default.</p> 180 </blockquote> 181 <h4 class="mansect"><a name="tag_20_67_10" id="tag_20_67_10"></a>STDOUT</h4> 182 <blockquote> 183 <p>Not used.</p> 184 </blockquote> 185 <h4 class="mansect"><a name="tag_20_67_11" id="tag_20_67_11"></a>STDERR</h4> 186 <blockquote> 187 <p>The standard error shall be used only for diagnostic messages.</p> 188 </blockquote> 189 <h4 class="mansect"><a name="tag_20_67_12" id="tag_20_67_12"></a>OUTPUT FILES</h4> 190 <blockquote> 191 <p>None.</p> 192 </blockquote> 193 <h4 class="mansect"><a name="tag_20_67_13" id="tag_20_67_13"></a>EXTENDED DESCRIPTION</h4> 194 <blockquote> 195 <p>None.</p> 196 </blockquote> 197 <h4 class="mansect"><a name="tag_20_67_14" id="tag_20_67_14"></a>EXIT STATUS</h4> 198 <blockquote> 199 <p>The following exit values shall be returned:</p> 200 <dl compact> 201 <dd></dd> 202 <dt> 0</dt> 203 <dd>Successful completion.</dd> 204 <dt>>0</dt> 205 <dd>An error occurred.</dd> 206 </dl> 207 </blockquote> 208 <h4 class="mansect"><a name="tag_20_67_15" id="tag_20_67_15"></a>CONSEQUENCES OF ERRORS</h4> 209 <blockquote> 210 <p>Default.</p> 211 </blockquote> 212 <hr> 213 <div class="box"><em>The following sections are informative.</em></div> 214 <h4 class="mansect"><a name="tag_20_67_16" id="tag_20_67_16"></a>APPLICATION USAGE</h4> 215 <blockquote> 216 <p>None.</p> 217 </blockquote> 218 <h4 class="mansect"><a name="tag_20_67_17" id="tag_20_67_17"></a>EXAMPLES</h4> 219 <blockquote> 220 <p>None.</p> 221 </blockquote> 222 <h4 class="mansect"><a name="tag_20_67_18" id="tag_20_67_18"></a>RATIONALE</h4> 223 <blockquote> 224 <p>The CONSEQUENCES OF ERRORS section does not require <i>ln</i> <b>-f</b> <i>a b</i> to remove <i>b</i> if a subsequent link 225 operation would fail.</p> 226 <p>Some historic versions of <i>ln</i> (including the one specified by the SVID) unlink the destination file, if it exists, by 227 default. If the mode does not permit writing, these versions prompt for confirmation before attempting the unlink. In these 228 versions the <b>-f</b> option causes <i>ln</i> not to attempt to prompt for confirmation.</p> 229 <p>This allows <i>ln</i> to succeed in creating links when the target file already exists, even if the file itself is not writable 230 (although the directory must be). Early proposals specified this functionality.</p> 231 <p>This volume of POSIX.1-2024 does not allow the <i>ln</i> utility to unlink existing destination paths by default for the 232 following reasons:</p> 233 <ul> 234 <li> 235 <p>The <i>ln</i> utility has historically been used to provide locking for shell applications, a usage that is incompatible with 236 <i>ln</i> unlinking the destination path by default. There was no corresponding technical advantage to adding this 237 functionality.</p> 238 </li> 239 <li> 240 <p>This functionality gave <i>ln</i> the ability to destroy the link structure of files, which changes the historical behavior of 241 <i>ln</i>.</p> 242 </li> 243 <li> 244 <p>This functionality is easily replicated with a combination of <a href="../utilities/rm.html"><i>rm</i></a> and <i>ln</i>.</p> 245 </li> 246 <li> 247 <p>It is not historical practice in many systems; BSD and BSD-derived systems do not support this behavior. Unfortunately, 248 whichever behavior is selected can cause scripts written expecting the other behavior to fail.</p> 249 </li> 250 <li> 251 <p>It is preferable that <i>ln</i> perform in the same manner as the <a href="../functions/link.html"><i>link</i>()</a> function, 252 which does not permit the target to exist already.</p> 253 </li> 254 </ul> 255 <p>This volume of POSIX.1-2024 retains the <b>-f</b> option to provide support for shell scripts depending on the SVID semantics. 256 It seems likely that shell scripts would not be written to handle prompting by <i>ln</i> and would therefore have specified the 257 <b>-f</b> option.</p> 258 <p>The <b>-f</b> option is an undocumented feature of many historical versions of the <i>ln</i> utility, allowing linking to 259 directories. These versions require modification.</p> 260 <p>Early proposals of this volume of POSIX.1-2024 also required a <b>-i</b> option, which behaved like the <b>-i</b> options in 261 <a href="../utilities/cp.html"><i>cp</i></a> and <a href="../utilities/mv.html"><i>mv</i></a>, prompting for confirmation before 262 unlinking existing files. This was not historical practice for the <i>ln</i> utility and has been omitted.</p> 263 <p>The <b>-L</b> and <b>-P</b> options allow for implementing both common behaviors of the <i>ln</i> utility. Earlier versions of 264 this standard did not specify these options and required the behavior now described for the <b>-L</b> option. Many systems by 265 default or as an alternative provided a non-conforming <i>ln</i> utility with the behavior now described for the <b>-P</b> option. 266 Since applications could not rely on <i>ln</i> following links in practice, the <b>-L</b> and <b>-P</b> options were added to 267 specify the desired behavior for the application.</p> 268 <p>The <b>-L</b> and <b>-P</b> options are ignored when <b>-s</b> is specified in order to allow an alias to be created to alter 269 the default behavior when creating hard links (for example, <a href="../utilities/alias.html"><i>alias</i></a> <i>ln</i>='<a href= 270 "../utilities/ln.html"><i>ln</i></a> <b>-L</b>'). They serve no purpose when <b>-s</b> is specified, since <i>source_file</i> is 271 then just a string to be used as the contents of the created symbolic link and need not exist as a file.</p> 272 <p>The specification ensures that <i>ln</i> <b>a</b> <b>a</b> with or without the <b>-f</b> option will not unlink the file 273 <b>a</b>. Earlier versions of this standard were unclear in this case.</p> 274 </blockquote> 275 <h4 class="mansect"><a name="tag_20_67_19" id="tag_20_67_19"></a>FUTURE DIRECTIONS</h4> 276 <blockquote> 277 <p>If this utility is directed to create a new directory entry that contains any bytes that have the encoded value of a 278 <newline> character, implementations are encouraged to treat this as an error. A future version of this standard may require 279 implementations to treat this as an error.</p> 280 </blockquote> 281 <h4 class="mansect"><a name="tag_20_67_20" id="tag_20_67_20"></a>SEE ALSO</h4> 282 <blockquote> 283 <p><a href="../utilities/chmod.html#tag_20_17"><i>chmod</i></a> , <a href="../utilities/find.html#"><i>find</i></a> , <a href= 284 "../utilities/pax.html#"><i>pax</i></a> , <a href="../utilities/readlink.html#tag_20_101"><i>readlink</i></a> , <a href= 285 "../utilities/realpath.html#tag_20_102"><i>realpath</i></a> , <a href="../utilities/rm.html#"><i>rm</i></a></p> 286 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href= 287 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p> 288 <p>XSH <a href="../functions/link.html#tag_17_304"><i>link</i></a> , <a href= 289 "../functions/unlink.html#tag_17_649"><i>unlink</i></a></p> 290 </blockquote> 291 <h4 class="mansect"><a name="tag_20_67_21" id="tag_20_67_21"></a>CHANGE HISTORY</h4> 292 <blockquote> 293 <p>First released in Issue 2.</p> 294 </blockquote> 295 <h4 class="mansect"><a name="tag_20_67_22" id="tag_20_67_22"></a>Issue 6</h4> 296 <blockquote> 297 <p>The <i>ln</i> utility is updated to include symbolic link processing as defined in the IEEE P1003.2b draft standard.</p> 298 </blockquote> 299 <h4 class="mansect"><a name="tag_20_67_23" id="tag_20_67_23"></a>Issue 7</h4> 300 <blockquote> 301 <p>Austin Group Interpretations 1003.1-2001 #164, #168, and #169 are applied.</p> 302 <p>SD5-XCU-ERN-27 is applied, adding a new paragraph to the RATIONALE.</p> 303 <p>SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p> 304 <p>The <b>-L</b> and <b>-P</b> options are added to make it implementation-defined whether the <i>ln</i> utility follows symbolic 305 links.</p> 306 <p>POSIX.1-2008, Technical Corrigendum 1, XCU/TC1-2008/0096 [136] is applied.</p> 307 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0113 [930] is applied.</p> 308 </blockquote> 309 <h4 class="mansect"><a name="tag_20_67_24" id="tag_20_67_24"></a>Issue 8</h4> 310 <blockquote> 311 <p>Austin Group Defect 251 is applied, encouraging implementations to disallow the creation of filenames containing any bytes that 312 have the encoded value of a <newline> character.</p> 313 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p> 314 <p>Austin Group Defect 1380 is applied, changing text using the term "link" in line with its updated definition.</p> 315 <p>Austin Group Defect 1457 is applied, adding <a href="../utilities/readlink.html"><i>readlink</i></a> and <a href= 316 "../utilities/realpath.html"><i>realpath</i></a> to the SEE ALSO section.</p> 317 <p>Austin Group Defect 1506 is applied, changing the EXIT STATUS section.</p> 318 </blockquote> 319 <div class="box"><em>End of informative text.</em></div> 320 <hr> 321 <p> </p> 322 <a href="#top"><span class="topOfPage">return to top of page</span></a><br> 323 <hr size="2" noshade> 324 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br> 325 POSIX™ is a Trademark of The IEEE.<br> 326 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br> 327 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href= 328 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a> 329 ]</font></center> 330 <hr size="2" noshade> 331 <div class="NAVHEADER"> 332 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 333 <tr class="nav"> 334 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/link.html" accesskey="P"><<< 335 Previous</a></td> 336 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 337 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/locale.html" accesskey="N">Next 338 >>></a></td> 339 </tr> 340 </table> 341 <hr align="left" width="100%"></div> 342 </body> 343 </html>