Symbolic Links & Hard Links








Imagine This:

Think of a file as a book in a library.

Now imagine two parts:

What

Analogy

📚 The book’s name on the shelf

Filename

📇 The card inside the book with all its info

Inode


📦 What is an Inode?

An inode is like a secret record that your Linux system keeps about each file.

It does NOT store the file's name.

Instead, the inode stores:

  • Who owns the file

  • When it was created or changed

  • What permissions it has (read/write etc.)

  • Where the actual content of the file is stored on disk

  • How big the file is

So:
Inode = All info about the file, except the name


🎯 Why Do We Need Inodes?

Linux doesn't look up files by name directly.

Instead:

  1. It sees the name of the file in a folder (just like a label).

  2. That name points to an inode number.

  3. Linux then uses that inode number to find the file's actual content and metadata.


✅ Simple Example:

Imagine you create a file:

echo "hello" > greeting.txt


Linux does this:

  • Adds an entry in the folder: greeting.txt → inode 12345

  • In inode 12345, it stores:

    • Size: 6 bytes

    • Owner: you

    • Data location: where "hello\n" is stored on disk

    • Permissions: read/write

    • Timestamps: created now


📂 Then, You Create a Hard Link:

ln greeting.txt copy.txt


Now your folder has:

greeting.txt → inode 12345

copy.txt     → inode 12345


Both names point to the same file!
If you edit one, the other changes too — because they are the same content, just with two names.


❌ But If You Delete One?

rm greeting.txt


Still OK!
copy.txt still points to inode 12345.
The file still exists because one pointer (hard link) is alive.


⚠️ But a Symlink (soft link) Is Different:

ln -s greeting.txt link.txt


This is like a shortcut that says:
“Look for a file named greeting.txt.”

If greeting.txt is deleted, the symlink (link.txt) is broken.


🛠 Why You Should Care (In Real Jobs):

Situation

Inode Helps You Understand

Log files not deleting

Process still holds inode — file data is alive even if name is gone

Disk full but space looks free

Inodes exhausted — can’t create new files

Check if 2 files are the same

Compare inode numbers — if same, they’re hard-linked

Create fast backups

Use hard links — no extra space used

Debug file permission issues

Check inode info for owner, perms


📌 Key Line to Remember:

A filename is just a label. The actual file lives in the inode.



What is an Inode? (Explained in Lehman's Terms)

Think of your Linux file system like a giant library.

  • Each file is like a book.

  • The name of the book (e.g., notes.txt) is stored in a directory — like the library catalog.

  • But the actual book (pages, content, metadata) lives on a different shelf.

An inode is like the index card that stores all details about the book except the name.


🗂️ Inode = File Metadata Holder (But Not the Filename)

When a file is created, the file system assigns it a unique inode number (just like a library card ID). That inode stores:

Property

Description

Size

File size in bytes

Owner

UID/GID of user who created it

Permissions

Read, write, execute for user/group/others

Timestamps

When it was created/modified/accessed

Link count

How many filenames point to this inode

Disk block pointers

Where actual file content lives on disk

📌 The filename is NOT stored in the inode — only in the directory that maps the name to the inode.


🛠️ Real-World Use Cases of Inodes

Use Case

Description

🔁 Hard links

Multiple filenames point to the same inode (shared file content)

💣 File not found, but space not freed

Deleted file with open inode still occupies disk (seen in logs or running processes)

📦 Full disk with free space?

No free inodes left — cannot create new files

🔍 Track duplicate files

Same inode → same content (hard links)

🔍 Check if files are the same

ls -li file1 file2 → same inode? They’re hard linked

🐞 Debug weird rm behavior

File still held open by process — inode active

📈 Filesystem optimization

Tune inode count for millions of small files


🔍 How to View Inode Info

# See inode of a file

ls -li file.txt


# Find all files with same inode (hard links)

find . -inum 123456


# Show inode count and free inodes

df -i



🎯 Why Should You Know About Inodes?

Role

Why it Matters

DevOps/SRE

Understand disk space issues, inode exhaustion, log cleanup, backup deduplication

System Admin

Manage file metadata, debug hidden disk usage

Programmers

Avoid data loss from improper file operations, understand symbolic vs hard links

Interview (FAANG)

Inodes appear in OS, file system, and Linux scripting questions


📦 Summary in One Line:

An inode is the metadata container of a file, minus the filename. It’s the heart of how Linux tracks files under the hood.”


Ref: https://tecadmin.net/what-is-soft-links-and-hard-links-in-linux/

Distributed by Gooyaabi Templates | Designed by OddThemes