The process of unlinking disassociates a name from the data on the volume without destroying the associated data. The data is still accessible as long as at least one link that points to it still exists. When the last link is removed, the space is considered free. A process ambiguously called undeleting allows the recreation of links to data that is no longer associated with a name. However, this process is not available on all systems and is often not reliable.
On POSIX-compliant operating systems, such as many Unix-variants, the reference count for a file or directory is returned by the stat() or fstat() system calls in the
st_nlink field of
struct stat. In contrast, programming language implementations that use reference counting rarely expose the reference count to the program being executed, since this information is just an implementation detail.
In the figure to the right, two hard links, named "LINK A.TXT" and "LINK B.TXT", point to the same physical data.
If the filename "LINK A.TXT" is opened in an editor, modified and saved, then those changes will be visible even if the filename "LINK B.TXT" is opened for viewing since both filenames point to the same data. The same is true if the file were opened as "LINK B.TXT" - or any other name associated with the data.
Any number of hard links to the physical data may be created. To access the data, a user only needs to specify the name of any existing link; the operating system will resolve the location of the actual data.
If one of the links is removed with the POSIX unlink function (for example, with the UNIX 'rm' command), then the data is still accessible through any other link that remains. If all of the links are removed and no process has the file open, then the space occupied by the data is freed, allowing it to be reused in the future. This semantic allows for deleting open files without affecting the process that uses them. This technique is commonly used to ensure that temporary files are deleted automatically on program termination, including the case of abnormal termination.
Hard links can only be created to files on the same file system. If a link to a file on a different file system is needed, it may be created with a symbolic link.