link — Create a hard link to a file

Format

link oldfile newfile

Description

link creates a hard link to an existing file. A link is a new directory entry that refers to the same file. This entry can be in the same directory that currently contains the file or in a different directory. The result is that you get a new path name that refers to the file. You can access the file under the old or new path name since both path names are of equal importance. If you use rm to remove one path name, the other remains and the file contents are still available under that name. The contents of the file do not disappear until the last remaining link associated with the file is removed.

Following the format, new becomes a new path name for the existing file old. If old names a symbolic link, link creates a hard link to the file that results from resolving the path name contained in the symbolic link.

Links are allowed to files only, not to directories. A file can have any number of links to it. Thus, you can establish any number of different path names for any file.

link is implemented as a shell built-in.

Localization

link uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • LC_SYNTAX
  • NLSPATH

See Localization for more information.

Exit values

0
Successful completion
1
Failure due to any of the following:
  • A file specified could not be found
  • No write permission on the directory intended to contain the link
  • No search permission on a path name component of old or new
  • No permission to access old
  • The path name of one of the arguments is a directory
  • The new link file already exists
2
Failure due to incorrect number of arguments

Related information

link, ln, rm