LN(1) General Commands Manual LN(1)

lnlink files

ln [-f] source_file target_file

ln [-f] source_file... target_dir

In the first synopsis form, the ln utility will create a new directory entry (link) for the file specified by the source_file operand, at the destination path specified by the target_file operand. This first synopsis form is 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 will result.

In the second synopsis form, the ln utility will create a new directory entry for each file specified by a source_file operand, at a destination path in the existing directory named by .

If the last operand specifies an existing file of a type not specified by the XSH specification, the behaviour is implementation-dependent.

The corresponding destination path for each source_file will be the concatenation of the target directory pathname, a slash character, and the last pathname component of the The second synopsis form will be assumed when the final operand names an existing directory.

For each source_file:

  1. If the destination path exists:
  2. If the -f option is not specified, ln will write a diagnostic message to standard error, do nothing more with the current source_file, and go on to any remaining source_files.

    Actions will be performed equivalent to the XSH specification function, called using destination as the argument. If this fails for any reason, ln will write a diagnostic message to standard error, do nothing more with the current source_file, and go on to any remaining source_files.

  3. Actions will be performed equivalent to the XSH specification link(3) function using source_file as the path1 argument, and the destination path as the path2 argument.

The ln utility supports the XBD specification, .

The following option is supported:

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

The following operands are supported:

source_file
A pathname of a file to be linked. This can be a regular or special file; whether a directory can be linked is implementation-dependent.
target_file
The pathname of the new directory entry to be created.
target_dir
A pathname of an existing directory in which the new directory entries are to be created.

Not used.

None.

The following environment variables affect the execution of ln :

Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
If set to a non-empty string value, override the values of all the other internationalisation variables.
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments).
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
Determine the location of message catalogues for the processing of LC_MESSAGES .

Default.

Not used.

Used only for diagnostic messages.

None.

None.

The following exit values are returned:

All the specified files were linked successfully.
An error occurred.

Default.

None.

None.

None.

chmod(1) , find(1) , pax(1) , rm(1) .

February 1997 posix.fail