![]() Example usage of ln utility | |
Original author(s) | AT&T Bell Laboratories |
---|---|
Developer(s) | Variousopen-source andcommercial developers |
Initial release | November 3, 1971; 53 years ago (1971-11-03) |
Operating system | Unix,Unix-like,IBM i |
Platform | Cross-platform |
Type | Command |
License | coreutils:GPLv3+ |
Theln
command is a standardUnix command utility used to create ahard link or asymbolic link (symlink) to an existing file or directory.[1] The use of a hard link allows multiplefilenames to be associated with the samefile since a hard link points to theinode of a given file, the data of which is stored ondisk. On the other hand, symbolic links are special files that refer to other files byname.[2]
Theln
command by default creates hard links, and when called with thecommand lineparameterln -s
creates symbolic links.[3] Mostoperating systems prevent hard links todirectories from being created since such a capability could disrupt the structure of afile system and interfere with the operation of other utilities.[4] Theln
command can however be used to create symbolic links to non-existent files.[2]
ln
appeared in Issue 2 of theX/Open Portability Guidelines.[5] The version ofln
bundled inGNUcoreutils was written by Mike Parker and David MacKenzie.[6]The command is available as a separate package forMicrosoft Windows as part of theUnxUtils collection ofnativeWin32ports of common GNU Unix-like utilities.[7] Theln command has also been ported to theIBM i operating system.[8]
Links allow more than one filename to refer to the same file as in the case of ahard link or act aspointers to a filename as in the case of asoft link. Both hard links and soft links can be created by theln
command. Specifically,
readlink
command line utility.[12] The symbolic link may contain an arbitrary string which does not refer to the location of an existing file. Such a symbolic link will fail until a file is created at the location which is contained by the symbolic link. By contrast, a symbolic link to an existing file will fail if the existing file is moved to a different location (or renamed).[9]Theln
utility on systems compliant with theSingle Unix Specification is specified in the Shell and Utilities (XCU) document, which forms a part of the Single Unix Specification.[13] A mostly identical document is part ofPOSIX.[5]
The specification describes two ways of invoking theln
utility. Specifically,
ln
utility creates a new hard link (directory entry) for the source file specified by thesource_file
operand at the destination path specified by thetarget_file
operand. However, if the-s
option is specified, a symbolic link is created.ln[-fs][-L|-P]source_filetarget_file
ln
utility creates a new hard link (directory entry), or if the-s
option is specified, a symbolic link, for each file specified by thesource_file
operand, at a destination path in an existing directory named by operandtarget_dir
.ln[-fs][-L|-P]source_file_1source_file_2...target_dir
The specification also specifies the command line options that must be supported:
-f
Force existing destination pathnames to be removed to allow the link.-L
For eachsource_file
operand that names a file that is a symbolic link, create a hard link to the file referenced by the symbolic link.-P
For eachsource_file
operand that names a file that is a symbolic link, create a (hard) link to the symbolic link itself.-s
Create symbolic links instead of hard links. If the -s option is specified, the -L and -P options are silently ignored.-L
and-P
is specified the last option specified determines the behavior of the utility.-s
option is not specified and neither a-L
nor a-P
option is specified, the implementation defines which of the-L
and-P
options will be used as the default.If neither target file nor target directory are specified, links will be created in the currentworking directory.
ln
– Shell and Utilities Reference,The Single UNIX Specification, Version 4 fromThe Open Groupln(1)
– Linux General CommandsManual