LinuxCommandLibrary

link

Create hard links between files

TLDR

Create a hard link from a new file to an existing file

$ link [path/to/existing_file] [path/to/new_file]
copy

SYNOPSIS

link FILE1 FILE2

PARAMETERS

FILE1
    Existing file to link to

FILE2
    Name of the new link to create

DESCRIPTION

link creates a hard link to an existing file. Unlike symlinks, hard links point directly to the file's inode, making the link indistinguishable from the original file. Both names refer to the same file data, and the file persists until all hard links are removed.

CAVEATS

Hard links cannot span filesystems. Cannot create hard links to directories (to prevent loops). Both files share the same inode and data. The ln command is more commonly used and offers more options.

HARD LINKS VS SYMLINKS

Hard links share the same inode; deleting the original doesn't affect the link. Symlinks are separate files containing a path; they break if the original is deleted.

SEE ALSO

ln(1), unlink(1), readlink(1), stat(1)

Copied to clipboard