Junior — Middle
Explain what a hard link is in a Linux file system and how it works.
sobes.tech AI
Answer from AI
A hard link in Linux is an additional name for an existing file. In the Linux file system, files are represented as inodes (index descriptors), which contain information about the file and point to the data on the disk. A hard link creates a new name that points to the same inode as the original file.
This means that:
- A file with two hard links is physically the same — the data is stored in one place.
- Deleting one of the names (links) does not delete the data as long as at least one hard link exists.
- Hard links cannot be created for directories (to avoid cycles) and between different file systems.
Example of creating a hard link:
ln original_file.txt hard_link.txt
Now, original_file.txt and hard_link.txt point to the same data.