Hard links in Linux

pikoTutorial - Feb 27 - - Dev Community

Welcome to the next pikoTutorial !

What is a hard link?

A hard link is essentially an additional name for an existing file on a file system. Unlike symbolic (soft) links, which point to a file by its path name, hard links are direct pointers to the file's inode. An inode is a data structure on a file system that stores information about a file, such as its size, permissions, and data block locations. Because hard links point directly to the inode, they remain valid even if the original file is moved or renamed. In other words, even if the file is removed, the file data remains accessible as long as at least one hard link points to that file.

How to create a hard link?

To create a hard link, use ln command together with the path to the original file and path to the hard link:

ln /path/to/original/file /path/to/hard/link
Enter fullscreen mode Exit fullscreen mode

Remember that hard links can only be created for files, not directories. This limitation helps to prevent file system corruption and unsolvable complexities in the directory structure, such as creating loops that could make the filesystem traversals difficult or impossible.

. . . . . . . . . . . . . . . . . . . . . . .