Core Distinctions Between Hard and Symbolic Links
Hard links and symbolic links (symlinks) establish alternative pathways to filesystem data, yet their internal implementations and constraints differ fundamentally.
| Attribute | Hard Link | Symbolic Link |
|---|---|---|
| Underlying Mechanism | Maps directly to the same inode as the original file | Creates a distinct file containing the pathname of the target |
| Cross-Device Support | Restricted to a single filesystem partition | Permitted across different filesystems and partitions |
| Directory Linking | Prohibited by default for directories | Fully supported for directories |
| Target Deletion Impact | Data remains accessible (inode reference count decrements) | Link becomes broken (dangling symlink) and unusable |
| Creation Syntax | ln original_path link_path |
ln -s original_path link_path |
| File Type Indicator | Appears as a standard regular file | Display attributes start with l in long list format |
| Storage Footprint | Consumes no additional data blocks | Requires minimal space to store the target path string |
Practical Demonstration
Establishing a Hard Link
echo "sample content" > primary_data.dat
ln primary_data.dat primary_hard.dat
Both primary_data.dat and primary_hard.dat reference the identical inode. Modifications made through either name instantly reflect in the other. Removing one name does not erase the actual data; the inode persists until its final reference is removed. This property is frequently leveraged in database operations—such as dropping massive MySQL tables—by creating a hard link beforehand to mitigate heavy I/O locking during the deletion phase.
Establishing a Symbolic Link
ln -s primary_data.dat primary_sym.dat
The file primary_sym.dat acts as an independent pointer storing the literal path "primary_data.dat". If primary_data.dat is erased, primary_sym.dat ceases to function, leaving an orphaned reference.
The Role of Inodes
In Linux, every file is internally tracked by a unique inode number. A hard link merely introduces an additional filename entry mapped to an existing inode. Conversely, a symlink generates a brand new inode with its own data blocks holding the textual location of the original file.
Inspect the inode identifiers using the following command:
ls -li primary_data.dat primary_hard.dat primary_sym.dat
The output will reveal that the hard link shares the exact inode number with the source file, whereas the symlink possesses a distinct inode identifier.