link Command

link File1 File2

The link command performs the link subroutine on a specified file. The link command does not issue error messages when the associated subroutine is unsuccessful; you must check the exit value to determine if the command completed normally. It returns a value of 0 if it succeeds, a value of 1 if too few or too many parameters are specified, and a value of 2 if its system call is unsuccessful.

Attention: The link command allows a user with root user authority to deal with unusual problems, such as moving an entire directory to a different part of the directory tree. It also permits you to create directories that cannot be reached or escaped from. Be careful to preserve the directory structure by observing the following rules:
  • Be certain every directory has a . (dot) link to itself.
  • Be certain every directory has a .. (dot dot) link to its parent directory.
  • Be certain every directory has no more than one link to itself or its parent directory.
  • Be certain every directory is accessible from the root of its file system.

Note: If the . (dot) entry has been destroyed and the fsck command is unable to repair it (a rare occurrence), you can use the link command to restore the . (dot) entry of the damaged directory. Use the link Dir Dir/. command where the Dir parameter is the name of the damaged directory. However, use this only as a last resort when the directory is destroyed and the fsck command is unable to fix it.

Although the linked files and directories can be removed by the unlink command, it's safer to use the rm or rmdir command.

To create an additional link for an existing file1, enter:

link file1 file2
Item Description