Links files.
To Link a File to a File
ln [ -f | -n ] [ -s ] SourceFile [ TargetFile ]
To Link a File or Files to a Directory
The ln command links the file designated in the SourceFile parameter to the file designated by the TargetFile parameter or to the same file name in another directory specified by the TargetDirectory parameter. By default, the ln command creates hard links. To use the ln command to create symbolic links, designate the -s flag.
A symbolic link is an indirect pointer to a file; its directory entry contains the name of the file to which it is linked. Symbolic links may span file systems and may refer to directories.
If you are linking a file to a new name, you can list only one file. If you are linking to a directory, you can list more than one file.
The TargetFile parameter is optional. If you do not designate a target file, the ln command creates a new file in your current directory. The new file inherits the name of the file designated in the SourceFile parameter. See example 5.
Notes:
- You cannot link files across file systems without using the -s flag.
- If TargetDirectory is already a symbolic link to a directory, then the ln command treats the existing target as a file. This means that a command such as ln -fs somepath/lname symdir will not follow the existing symbolic link of symdir, instead it will create a new symbolic link from somepath/lname to symdir.
| Item | Description | 
|---|---|
| -f | Causes the ln command to replace any destination paths that already exist. If a destination path already exists and the -f flag is not specified, the ln command writes a diagnostic message to standard error without creating a new link and continues to link the remaining SourceFiles. | 
| -n | Specifies that if the link is an existing file, do not overwrite the contents of the file. The -f flag overrides this flag. This is the default behavior. | 
| -s | Causes the ln command to create symbolic links. A
symbolic link contains the name of the file to which it is linked.
The referenced file is used when an open operation is performed on
the link. A stat call on a symbolic link returns the linked-to
file; an lstat call must be done to obtain information about
the link. The readlink call may be used to read the contents
of a symbolic link. Symbolic links can span file systems and refer
to directories. Note: Absolute path names must be used when specifying the SourceFile parameter for the -s flag. If the absolute path name is not designated, unexpected results may occur when the SourceFile and the TargetFile parameters are located in different directories. The source file does not need to exist before creating the symbolic link. | 
This command returns the following exit values:
| Item | Description | 
|---|---|
| 0 | All specified files were successfully linked. | 
| >0 | An error occurred. | 
ln  -f chap1  introln  index  manualNote: intro in example 1 is the name of a file; manual in example 2 is a directory that already exists.
ln  chap2  jim/chap3  /home/manualln  manual/* .Note: You must type a space between the asterisk and the period.
ln -s /tmp/toc tocTo achieve identical results without designating the TargetFile parameter, enter:
ln -s /tmp/toc| Item | Description | 
|---|---|
| /usr/bin/ln | Contains the ln command. |