In this lesson, you’ll learn how Linux uses inodes and hard links to share files efficiently—without duplicating data. We’ll cover:Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
- What inodes and links are
- Creating hard links
- Deletion behavior
- Common limitations
- Permission management
What Are Inodes and Hard Links?
Every file on a Linux filesystem is represented by an inode, which stores metadata (permissions, timestamps, disk block locations). A hard link is simply another directory entry that points to the same inode. Consider Aaron’s photo of his dog Milo, saved as:| Term | Description |
|---|---|
| Inode | Unique number with file metadata & data-block pointers |
| Links | Count of directory entries referencing this inode (starts at 1 for a new file) |
| Data | Actual content blocks on disk |
When you open or read a file, the kernel looks up its name, retrieves the inode (e.g.,
52946177), and accesses the data blocks. Hard links simply give you multiple names for the same inode.Sharing Files Without Duplication
Copying large directories wastes disk space:- Source:
/home/aaron/Pictures/family_dog.jpg - Link name:
/home/jane/Pictures/family_dog.jpg
stat:
Deletion Behavior
When Aaron removes his link, the data remains as long as one hard link exists:- Link count drops to 1
- File content is still intact for Jane
Hard Link vs. Copy
| Operation | Disk Usage | Link Count | Independent Changes? |
|---|---|---|---|
| Copy | +100% | 1 each | Yes |
| Hard Link | +0% | >1 | No (shared inode) |
- You cannot create hard links to directories (prevents filesystem loops).
- Hard links must reside on the same filesystem—cross-device linking is not allowed.
Managing Permissions for Shared Files
Since file permissions live in the inode, updating them on one hard link affects all links. To let both Aaron and Jane read/write:-
Add both users to a common group (
family): -
Set group read/write permissions: