LN(1)                      POSIX Programmer's Manual                     LN(1)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       ln -- link files

SSYYNNOOPPSSIISS
       ln [[-fs]] [[-L|-P]] _s_o_u_r_c_e___f_i_l_e _t_a_r_g_e_t___f_i_l_e

       ln [[-fs]] [[-L|-P]] _s_o_u_r_c_e___f_i_l_e... _t_a_r_g_e_t___d_i_r

DDEESSCCRRIIPPTTIIOONN
       In the first synopsis form, the _l_n utility shall create a new directory
       entry (link) at the destination path specified by the _t_a_r_g_e_t___f_i_l_e
       operand. If the --ss option is specified, a symbolic link shall be
       created for the file specified by the _s_o_u_r_c_e___f_i_l_e 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 _l_n utility shall create a new
       directory entry (link), or if the --ss option is specified a symbolic
       link, for each file specified by a _s_o_u_r_c_e___f_i_l_e operand, at a
       destination path in the existing directory named by _t_a_r_g_e_t___d_i_r.

       If the last operand specifies an existing file of a type not specified
       by the System Interfaces volume of POSIX.1-2017, the behavior is
       implementation-defined.

       The corresponding destination path for each _s_o_u_r_c_e___f_i_l_e 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 _s_o_u_r_c_e___f_i_l_e.  The second synopsis form shall
       be assumed when the final operand names an existing directory.

       For each _s_o_u_r_c_e___f_i_l_e:

        1. If the destination path exists and was created by a previous step,
           it is unspecified whether _l_n shall write a diagnostic message to
           standard error, do nothing more with the current _s_o_u_r_c_e___f_i_l_e, and
           go on to any remaining _s_o_u_r_c_e___f_i_l_es; or will continue processing
           the current _s_o_u_r_c_e___f_i_l_e.  If the destination path exists:

            a. If the --ff option is not specified, _l_n shall write a diagnostic
               message to standard error, do nothing more with the current
               _s_o_u_r_c_e___f_i_l_e, and go on to any remaining _s_o_u_r_c_e___f_i_l_es.

            b. If the destination path names the same directory entry as the
               current _s_o_u_r_c_e___f_i_l_e _l_n shall write a diagnostic message to
               standard error, do nothing more with the current _s_o_u_r_c_e___f_i_l_e,
               and go on to any remaining _s_o_u_r_c_e___f_i_l_es_.

            c. Actions shall be performed equivalent to the _u_n_l_i_n_k() function
               defined in the System Interfaces volume of POSIX.1-2017, called
               using the destination path as the _p_a_t_h argument. If this fails
               for any reason, _l_n shall write a diagnostic message to standard
               error, do nothing more with the current _s_o_u_r_c_e___f_i_l_e, and go on
               to any remaining _s_o_u_r_c_e___f_i_l_es.

        2. If the --ss option is specified, actions shall be performed
           equivalent to the _s_y_m_l_i_n_k() function with _s_o_u_r_c_e___f_i_l_e as the _p_a_t_h_1
           argument and the destination path as the _p_a_t_h_2 argument. The _l_n
           utility shall do nothing more with _s_o_u_r_c_e___f_i_l_e and shall go on to
           any remaining files.

        3. If _s_o_u_r_c_e___f_i_l_e is a symbolic link:

            a. If the --PP option is in effect, actions shall be performed
               equivalent to the _l_i_n_k_a_t() function with _s_o_u_r_c_e___f_i_l_e as the
               _p_a_t_h_1 argument, the destination path as the _p_a_t_h_2 argument,
               AT_FDCWD as the _f_d_1 and _f_d_2 arguments, and zero as the _f_l_a_g
               argument.

            b. If the --LL option is in effect, actions shall be performed
               equivalent to the _l_i_n_k_a_t() function with _s_o_u_r_c_e___f_i_l_e as the
               _p_a_t_h_1 argument, the destination path as the _p_a_t_h_2 argument,
               AT_FDCWD as the _f_d_1 and _f_d_2 arguments, and AT_SYMLINK_FOLLOW as
               the _f_l_a_g argument.

           The _l_n utility shall do nothing more with _s_o_u_r_c_e___f_i_l_e and shall go
           on to any remaining files.

        4. Actions shall be performed equivalent to the _l_i_n_k() function
           defined in the System Interfaces volume of POSIX.1-2017 using
           _s_o_u_r_c_e___f_i_l_e as the _p_a_t_h_1 argument, and the destination path as the
           _p_a_t_h_2 argument.

OOPPTTIIOONNSS
       The _l_n utility shall conform to the Base Definitions volume of
       POSIX.1-2017, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s.

       The following options shall be supported:

       --ff        Force existing destination pathnames to be removed to allow
                 the link.

       --LL        For each _s_o_u_r_c_e___f_i_l_e operand that names a file of type
                 symbolic link, create a (hard) link to the file referenced by
                 the symbolic link.

       --PP        For each _s_o_u_r_c_e___f_i_l_e operand that names a file of type
                 symbolic link, create a (hard) link to the symbolic link
                 itself.

       --ss        Create symbolic links instead of hard links. If the --ss option
                 is specified, the --LL and --PP options shall be silently
                 ignored.

       Specifying more than one of the mutually-exclusive options --LL and --PP
       shall not be considered an error. The last option specified shall
       determine the behavior of the utility (unless the --ss option causes it
       to be ignored).

       If the --ss option is not specified and neither a --LL nor a --PP option is
       specified, it is implementation-defined which of the --LL and --PP options
       will be used as the default.

OOPPEERRAANNDDSS
       The following operands shall be supported:

       _s_o_u_r_c_e___f_i_l_e
                 A pathname of a file to be linked. If the --ss option is
                 specified, no restrictions on the type of file or on its
                 existence shall be made. If the --ss option is not specified,
                 whether a directory can be linked is implementation-defined.

       _t_a_r_g_e_t___f_i_l_e
                 The pathname of the new directory entry to be created.

       _t_a_r_g_e_t___d_i_r
                 A pathname of an existing directory in which the new
                 directory entries are created.

SSTTDDIINN
       Not used.

IINNPPUUTT FFIILLEESS
       None.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       The following environment variables shall affect the execution of _l_n:

       _L_A_N_G      Provide a default value for the internationalization
                 variables that are unset or null. (See the Base Definitions
                 volume of POSIX.1-2017, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n
                 _V_a_r_i_a_b_l_e_s for the precedence of internationalization
                 variables used to determine the values of locale categories.)

       _L_C___A_L_L    If set to a non-empty string value, override the values of
                 all the other internationalization variables.

       _L_C___C_T_Y_P_E  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).

       _L_C___M_E_S_S_A_G_E_S
                 Determine the locale that should be used to affect the format
                 and contents of diagnostic messages written to standard
                 error.

       _N_L_S_P_A_T_H   Determine the location of message catalogs for the processing
                 of _L_C___M_E_S_S_A_G_E_S.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       Default.

SSTTDDOOUUTT
       Not used.

SSTTDDEERRRR
       The standard error shall be used only for diagnostic messages.

OOUUTTPPUUTT FFIILLEESS
       None.

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
       None.

EEXXIITT SSTTAATTUUSS
       The following exit values shall be returned:

        0    All the specified files were linked successfully.

       >0    An error occurred.

CCOONNSSEEQQUUEENNCCEESS OOFF EERRRROORRSS
       Default.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

EEXXAAMMPPLLEESS
       None.

RRAATTIIOONNAALLEE
       The CONSEQUENCES OF ERRORS section does not require _l_n --ff _a _b to remove
       _b if a subsequent link operation would fail.

       Some historic versions of _l_n (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 --ff option causes _l_n not to
       attempt to prompt for confirmation.

       This allows _l_n 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-2017 does not allow the _l_n utility to unlink
       existing destination paths by default for the following reasons:

        *  The _l_n utility has historically been used to provide locking for
           shell applications, a usage that is incompatible with _l_n unlinking
           the destination path by default. There was no corresponding
           technical advantage to adding this functionality.

        *  This functionality gave _l_n the ability to destroy the link
           structure of files, which changes the historical behavior of _l_n.

        *  This functionality is easily replicated with a combination of _r_m
           and _l_n.

        *  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.

        *  It is preferable that _l_n perform in the same manner as the _l_i_n_k()
           function, which does not permit the target to exist already.

       This volume of POSIX.1-2017 retains the --ff 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 _l_n and would
       therefore have specified the --ff option.

       The --ff option is an undocumented feature of many historical versions of
       the _l_n utility, allowing linking to directories. These versions require
       modification.

       Early proposals of this volume of POSIX.1-2017 also required a --ii
       option, which behaved like the --ii options in _c_p and _m_v, prompting for
       confirmation before unlinking existing files. This was not historical
       practice for the _l_n utility and has been omitted.

       The --LL and --PP options allow for implementing both common behaviors of
       the _l_n utility. Earlier versions of this standard did not specify these
       options and required the behavior now described for the --LL option. Many
       systems by default or as an alternative provided a non-conforming _l_n
       utility with the behavior now described for the --PP option. Since
       applications could not rely on _l_n following links in practice, the --LL
       and --PP options were added to specify the desired behavior for the
       application.

       The --LL and --PP options are ignored when --ss is specified in order to
       allow an alias to be created to alter the default behavior when
       creating hard links (for example, _a_l_i_a_s _l_n='_l_n --LL').  They serve no
       purpose when --ss is specified, since _s_o_u_r_c_e___f_i_l_e 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 _l_n aa aa with or without the --ff option
       will not unlink the file aa.  Earlier versions of this standard were
       unclear in this case.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _c_h_m_o_d, _f_i_n_d, _p_a_x, _r_m

       The Base Definitions volume of POSIX.1-2017, _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t
       _V_a_r_i_a_b_l_e_s, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s

       The System Interfaces volume of POSIX.1-2017, _l_i_n_k(), _u_n_l_i_n_k()

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  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.opengroup.org/unix/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 .



IEEE/The Open Group                  2017                                LN(1)
