When you open a file in Linux, you're seeing just the tip of the iceberg. Beneath the surface is a structure called an inode—and understanding how it works is the key to making sense of hard links, soft links, and what really happens when you rename or delete a file.
What’s an Inode?
An inode is a hidden record in the Linux file system that stores everything about a file except its name. It holds details like:
- Where the file’s content lives on the disk
- The file’s size and timestamps
- Ownership and permissions
Each file has a unique inode number. Think of it as the file’s true identity. The name you see in a folder is just a label that points to it.
Hard Links: Multiple Labels, One File
Creating a hard link is like putting a second label on the same package. Both names point to the same inode. That means they’re actually the same file.
If you change the contents of one, the other reflects those changes instantly. If you delete one, the other stays alive—because the inode still exists and another name still leads to it.
ln original.txt copy.txt
In this example, original.txt
and copy.txt
are hard links. They’re just two names for the same file.
Soft Links: A Shortcut with Limits
Soft links (also called symbolic links) work differently. Instead of pointing directly to the inode, they point to the file name.
This means they’re more like shortcuts. If the target file is moved or deleted, the soft link breaks because it’s looking for a name that no longer exists.
ln -s original.txt shortcut.txt
Now, shortcut.txt
leads to original.txt
. But if original.txt
disappears, the shortcut becomes useless.
Why Inodes Matter
Understanding inodes reveals why links behave the way they do. Hard links rely on inode numbers—so they’re deeply connected. Soft links rely on file names—so they’re more fragile.
Inodes also explain why deleting a file doesn’t always erase its contents. If another hard link still points to the same inode, the data stays.
How to See Inodes in Action
You can view inode numbers with a simple command:
ls -i
Or check detailed info using:
stat filename.txt
This shows the inode number and how many links point to it. Try creating hard and soft links, then inspect them using these tools. You’ll see Linux's hidden architecture come to life.
Inodes are quiet, but powerful. They don’t ask for attention—but once you understand them, you’ll never look at file names the same way again.
Top comments (0)