Links & Inodes in Linux
What Is an Inode?
In Linux, a filesystem uses an inode (index node) to store information about a file or directory. Each inode has a number that identifies it within its filesystem.
An inode stores metadata such as:
- File type and permissions
- Owner and group IDs
- File size
- Timestamps
- References to the file's data blocks
- Link count
An inode does not store the filename. A directory maps filenames to inode numbers. This separation allows multiple filenames to reference the same underlying file data.
Viewing Inode Numbers
Use ls -i to display inode numbers:
ls -liExample output:
105012 -rw-r--r-- 1 ubuntu ubuntu 120 Oct 20 10:30 telusko.txt
105019 -rw-r--r-- 1 ubuntu ubuntu 250 Oct 20 10:32 shell.txtThe first column contains the inode number.
Note: Inode numbers are unique within a filesystem, not necessarily across the entire Linux system. Two files on different filesystems can have the same inode number.
What Are Links in Linux?
A link provides another way to access a file. Linux supports two main types:

1. Hard Links
A hard link creates another name for the same underlying file data. Both names refer to the same inode, so they share the same content and metadata stored in that inode.
Creating a Hard Link
Suppose telusko.txt already exists. Create a hard link with:
ln telusko.txt teluskoai.txtHere:
telusko.txtis the existing file.teluskoai.txtis the new hard link.
Both filenames now refer to the same file data.
Verify the Inode Number
ls -li telusko.txt teluskoai.txtExample output:
105012 -rw-r--r-- 2 ubuntu ubuntu 120 Oct 20 10:30 telusko.txt
105012 -rw-r--r-- 2 ubuntu ubuntu 120 Oct 20 10:30 teluskoai.txtNotice two important details:
- Both filenames have the same inode number:
105012. - The link count is
2, meaning two hard links refer to that inode.
Changes Are Visible Through Both Names
If you modify the file through either name, reading it through the other name shows the same updated content.
For example:
echo "Linux is powerful" >> telusko.txt
cat teluskoai.txtThe new line appears because both names access the same underlying file.
Deleting One Name Does Not Delete the Data Immediately
rm telusko.txt
cat teluskoai.txtThe content remains accessible through teluskoai.txt.
Removing one hard link removes only that directory entry. The filesystem can reclaim the file's data when no hard links remain and no process is still holding the file open.
Limitations of Hard Links
- Hard links generally cannot be created for directories by ordinary users.
- They cannot cross filesystem boundaries.
- They refer to the same inode rather than to a pathname, so renaming or removing one filename does not invalidate the other.
2. Symbolic Links (Soft Links)
A symbolic link, also called a soft link, is a separate filesystem object that stores the path to another file or directory.
Unlike a hard link, it has its own inode. When you access the symbolic link, Linux follows the stored path to locate the target.
Creating a Symbolic Link
Suppose shell.txt exists. Create a symbolic link using ln -s:
ln -s shell.txt shellai.txtHere:
shell.txtis the target.shellai.txtis the symbolic link.-stellslnto create a symbolic link.
Verify the Link
ls -li shell.txt shellai.txtExample output:
105019 -rw-r--r-- 1 ubuntu ubuntu 250 Oct 20 10:32 shell.txt
105025 lrwxrwxrwx 1 ubuntu ubuntu 9 Oct 20 10:35 shellai.txt -> shell.txtThe inode numbers differ because the link and target are separate filesystem objects.
The l at the beginning of the symbolic link's permission string indicates a symbolic link. The arrow shows the stored target path.
Changes to the Target Are Visible Through the Link
echo "Learning Linux links" >> shell.txt
cat shellai.txtThe updated content is visible through shellai.txt because the link resolves to shell.txt.
What Happens When the Target Is Deleted?
rm shell.txt
cat shellai.txtThe symbolic link remains, but its target path no longer resolves. This is called a broken or dangling symbolic link.
The link itself can still be listed and removed:
ls -l shellai.txt
rm shellai.txtRemoving a symbolic link does not delete its target.
Advantages of Symbolic Links
- Can point to files or directories.
- Can reference targets on another filesystem.
- Can refer to a target using a pathname.
- Remain useful when you want a convenient alternate path to a file or directory.

Quick Reference
| Command | Purpose |
|---|---|
ls -li | List files with inode numbers |
ln original.txt hard.txt | Create a hard link |
ln -s original.txt soft.txt | Create a symbolic link |
ls -l soft.txt | View a symbolic link and its target path |
readlink soft.txt | Display the path stored in a symbolic link |
rm hard.txt | Remove one hard-link directory entry |
rm soft.txt | Remove the symbolic link, not its target |
Summary
- An inode stores file metadata and references to data; it does not store the filename.
- A directory associates filenames with inode numbers.
- Hard links share an inode and provide multiple names for the same underlying file.
- Symbolic links have their own inode and store a path to a target.
- Removing one hard link does not remove the data if other references remain.
- A symbolic link can become broken when its target path no longer resolves.
- Use
lnfor hard links,ln -sfor symbolic links, andls -lito inspect inode numbers.
Written By: Muskan Garg
How is this guide?
Last updated on
