NAME
ln — link
files
SYNOPSIS
ln |
[-fs] source_file
target_file |
ln |
[-fs] source_file
... target_dir |
DESCRIPTION
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 -s 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 -s 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 IEEE Std 1003.1-2001 (“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, 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:
- If the destination path exists:
- If the
-foption is not specified,lnshall write a diagnostic message to standard error, do nothing more with the current source_file, and go on to any remaining source_files. - Actions shall be performed equivalent to the
unlink(3) function defined in the System Interfaces
volume of IEEE Std 1003.1-2001
(“POSIX.1”), called using
destination
as the
path
argument. If this fails for any reason,
lnshall write a diagnostic message to standard error, do nothing more with the current source_file, and go on to any remaining source_files.
- If the
- If the
-soption is specified,lnshall create a symbolic link named by the destination path and containing as its pathname source_file. Thelnutility shall do nothing more with source_file and shall go on to any remaining files. - If source_file is a symbolic link, actions shall be
performed equivalent to the link(3) function using the
object that source_file references as the
path1 argument and the destination path as the
path2 argument. The
lnutility shall do nothing more with source_file and shall go on to any remaining files. - Actions shall be performed equivalent to the link(3) function defined in the System Interfaces volume of IEEE Std 1003.1-2001 (“POSIX.1”) using source_file as the path1 argument, and the destination path as the path2 argument.
OPTIONS
The ln utility shall conform to the Base
Definitions volume of IEEE Std 1003.1-2001
(“POSIX.1”), xbd_chap12(7).
The following option shall be supported:
OPERANDS
The following operands shall be supported:
- source_file
- A pathname of a file to be linked. If the
-soption is specified, no restrictions on the type of file or on its existence shall be made. If the-soption is not specified, whether a directory can be linked is implementation-defined. - 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 created.
STDIN
Not used.
INPUT FILES
None.
ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of
ln:
LANG- Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of IEEE Std 1003.1-2001 (“POSIX.1”), Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
LC_ALL- If set to a non-empty string value, override the values of all the other internationalization variables.
LC_CTYPE- 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- Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
NLSPATH- [
XSI] Determine the location of message catalogs for the processing of LC_MESSAGES .
ASYNCHRONOUS EVENTS
Default.
STDOUT
Not used.
STDERR
The standard error shall be used only for diagnostic messages.
OUTPUT FILES
None.
EXTENDED DESCRIPTION
None.
EXIT STATUS
The following exit values shall be returned:
CONSEQUENCES OF ERRORS
Default.
APPLICATION USAGE
None.
EXAMPLES
None.
RATIONALE
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
-f 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 IEEE Std 1003.1-2001
(“POSIX.1”) does not allow the
ln utility to unlink existing destination paths by
default for the following reasons:
- The
lnutility has historically been used to provide locking for shell applications, a usage that is incompatible withlnunlinking the destination path by default. There was no corresponding technical advantage to adding this functionality. - This functionality gave
lnthe ability to destroy the link structure of files, which changes the historical behavior ofln. - This functionality is easily replicated with a combination of
rm(1) and
ln. - 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
lnperform in the same manner as the link(3) function, which does not permit the target to exist already.
This volume of IEEE Std 1003.1-2001
(“POSIX.1”) retains the -f
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
-f option.
The -f 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 IEEE Std
1003.1-2001 (“POSIX.1”) also required a
-i option, which behaved like the
-i options in cp(1) and
mv(1), prompting for confirmation before unlinking
existing files. This was not historical practice for the
ln utility and has been omitted.
FUTURE DIRECTIONS
None.
SEE ALSO
chmod(1), find(1), pax(1), rm(1), the System Interfaces volume of IEEE Std 1003.1-2001 (“POSIX.1”), link(3), unlink(3)
CHANGE HISTORY
First released in Issue 2.
Issue 6
The ln utility is updated to include
symbolic link processing as defined in the IEEE P1003.2b draft standard.
End of informative text. footer end