27.4 Creating a Hard Link Using Ln on a Linux Client

Typically, you create hard links by using clients (like NFS) that have existing commands to manipulate links. This section explains how to create a hard link in a volume by accessing the volume from a Linux workstation, then using the Link (ln) command to create a hard link. For help with syntax and options, refer to the Link Manual Page from a Linux client. At a terminal console, enter

man 2 ln

Creating a hard link to a file does not copy the contents of the file to the new location; it simply makes a new name by which the file can be known, in addition to the file’s existing name or names. All of the names are equally real, and no one of them is preferred to the others except regarding access control and directory space quotas. For information, see Section 27.1, Understanding Hard Links.

The actual content of the file is maintained in only the original file. Users in different directories can use hard links to access and share the same file. A single user can use hard links to access a file from different directories.

Prerequisites

Procedure

To create a hard link, use the Link (ln) command from a Linux client.

  1. At a terminal console, enter

    ln /path/filename /linkpath/linkfilename
    

    Replace /path/filename with the pathname for the original file. Replace /linkpath/linkfilename with the pathname for the hard linked filename.

    For example, to link the file /tmp/timetest to /usr/tmp/t1, enter

    ln /tmp/timetest /usr/tmp/t1
    

    The file can now be referred to by either name. You can delete the original name or any link name, but the contents of the file are not removed until the final name is deleted.