ln [ ][ ] source_filetarget_file
ln [ ][ ] source_file ... target_dir
The following environment variables shall affect the execution of ln:
" LANG "10 Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1 Section 8.2,Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
" LC_ALL "10 If set to a non-empty string value, override the values of all the other internationalization variables.
" LC_CTYPE "10 Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments).
" LC_MESSAGES "10
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
" NLSPATH "10 Determine the location of message catalogs for the processing of LC_MESSAGES.
The standard error shall be used only for diagnostic messages.
The following exit values shall be returned:
" 0" 6 All the specified files were linked successfully.
>0 6 An error occurred.
The CONSEQUENCES OF ERRORS section does not require ln ab to remove b if a subsequent link operation would fail.
Some historic versions of ln (including the one specified by the SVID) unlink the destination file, if it exists, by default. If the mode does not permit writing, these versions prompt for confirmation before attempting the unlink. In these versions the option causes ln not to attempt to prompt for confirmation.
This allows ln to succeed in creating links when the target file already exists, even if the file itself is not writable (although the directory must be). Early proposals specified this functionality.
This volume of POSIX.1 does not allow the ln utility to unlink existing destination paths by default for the following reasons:
" *" 4 The ln utility has historically been used to provide locking for shell applications, a usage that is incompatible with ln unlinking the destination path by default. There was no corresponding technical advantage to adding this functionality.
" *" 4 This functionality gave ln the ability to destroy the link structure of files, which changes the historical behavior of ln.
" *" 4 This functionality is easily replicated with a combination of rm and ln.
" *" 4 It is not historical practice in many systems; BSD and BSD-derived systems do not support this behavior. Unfortunately, whichever behavior is selected can cause scripts written expecting the other behavior to fail.
" *" 4 It is preferable that ln perform in the same manner as the link () function, which does not permit the target to exist already.
This volume of POSIX.1 retains the option to provide support for shell scripts depending on the SVID semantics. It seems likely that shell scripts would not be written to handle prompting by ln and would therefore have specified the option.
The option is an undocumented feature of many historical versions of the ln utility, allowing linking to directories. These versions require modification.
Early proposals of this volume of POSIX.1 also required a option, which behaved like the options in cp and mv, prompting for confirmation before unlinking existing files. This was not historical practice for the ln utility and has been omitted.
The and options allow for implementing both common behaviors of the ln utility. Earlier versions of this standard did not specify these options and required the behavior now described for the option. Many systems by default or as an alternative provided a non-conforming ln utility with the behavior now described for the option. Since applications could not rely on ln following links in practice, the and options were added to specify the desired behavior for the application.
The and options are ignored when is specified in order to allow an alias to be created to alter the default behavior when creating hard links (for example, alias ln=' ln '). They serve no purpose when is specified, since source_file is then just a string to be used as the contents of the created symbolic link and need not exist as a file.
The specification ensures that ln a a with or without the option will not unlink the file a. Earlier versions of this standard were unclear in this case.
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, Copyright (C) 2013 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. (This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.unix.org/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
In the first synopsis form, the ln utility shall create a new directory entry (link) at the destination path specified by the target_file operand. If the option is specified, a symbolic link shall be created for the file specified by the source_file operand. This first synopsis form shall be assumed when the final operand does not name an existing directory; if more than two operands are specified and the final is not an existing directory, an error shall result.
In the second synopsis form, the ln utility shall create a new directory entry (link), or if the option is specified a symbolic link, for each file specified by a source_file operand, at a destination path in the existing directory named by target_dir.
If the last operand specifies an existing file of a type not specified by the System Interfaces volume of POSIX.1 the behavior is implementation-defined.
The corresponding destination path for each source_file shall be the concatenation of the target directory pathname, a <slash> character if the target directory pathname did not end in a <slash>, and the last pathname component of the source_file. The second synopsis form shall be assumed when the final operand names an existing directory.
For each source_file:
" 1." 4 If the destination path exists and was created by a previous step, it is unspecified whether ln shall write a diagnostic message to standard error, do nothing more with the current source_file, and go on to any remaining source_files; or will continue processing the current source_file. If the destination path exists:
" a." 4 If the option is not specified, ln shall write a diagnostic message to standard error, do nothing more with the current source_file, and go on to any remaining source_files.
" b." 4 If destination names the same directory entry as the current source_file ln shall write a diagnostic message to standard error, do nothing more with the current source_file, and go on to any remaining source_files.
" c." 4 Actions shall be performed equivalent to the unlink () function defined in the System Interfaces volume of POSIX.1 called using destination as the path argument. If this fails for any reason, ln shall write a diagnostic message to standard error, do nothing more with the current source_file, and go on to any remaining source_files.
" 2." 4 If the option is specified, actions shall be performed equivalent to the symlink () function with source_file as the path1 argument and the destination path as the path2 argument. The ln utility shall do nothing more with source_file and shall go on to any remaining files.
" 3." 4 If source_file is a symbolic link:
" a." 4 If the option is in effect, actions shall be performed equivalent to the linkat () function with source_file as the path1 argument, the destination path as the path2 argument, AT_FDCWD as the fd1 and fd2 arguments, and zero as the flag argument.
" b." 4 If the option is in effect, actions shall be performed equivalent to the linkat () function with source_file as the path1 argument, the destination path as the path2 argument, AT_FDCWD as the fd1 and fd2 arguments, and AT_SYMLINK_FOLLOW as the flag argument.
The ln utility shall do nothing more with source_file and shall go on to any remaining files.
" 4." 4 Actions shall be performed equivalent to the link () function defined in the System Interfaces volume of POSIX.1 using source_file as the path1 argument, and the destination path as the path2 argument.
The ln utility shall conform to the Base Definitions volume of POSIX.1 Section 12.2,Utility Syntax Guidelines.
The following options shall be supported:
" "10 Force existing destination pathnames to be removed to allow the link.
" "10 For each source_file operand that names a file of type symbolic link, create a (hard) link to the file referenced by the symbolic link.
" "10 For each source_file operand that names a file of type symbolic link, create a (hard) link to the symbolic link itself.
" "10 Create symbolic links instead of hard links. If the option is specified, the and options shall be silently ignored.
Specifying more than one of the mutually-exclusive options and shall not be considered an error. The last option specified shall determine the behavior of the utility (unless the option causes it to be ignored).
If the option is not specified and neither a nor a option is specified, it is implementation-defined which of the and options will be used as the default.
The following operands shall be supported:
" source_file "10 A pathname of a file to be linked. If the option is specified, no restrictions on the type of file or on its existence shall be made. If the option is not specified, whether a directory can be linked is implementation-defined.
" target_file "10 The pathname of the new directory entry to be created.
" target_dir "10 A pathname of an existing directory in which the new directory entries are created.
chmod, find, pax, rm The Base Definitions volume of POSIX.1 Chapter 8,Environment Variables, Section 12.2,Utility Syntax Guidelines The System Interfaces volume of POSIX.1 link ( ), unlink ( )