Skip to content
Calcrivo

Hard Link Count Calculator

Track hard link counts and their effect on inode reference counting and deletion.

Inputs

New Link Count (nlink)

2

What Happens

nlink = 2 — the inode and its data remain on disk; unlinking any single name never frees the data while nlink > 0.

Data Deallocated?

false

Disk Space Freed (MB)

0.00

Step by step

  1. Values used

    Current stat nlink Value = 1; Operation = Create additional hard link(s); Number of Links to Add/Remove = 1; File Data Size (MB) = 100

  2. New link count

    new_nlink = current_nlink ± delta (data freed only when new_nlink reaches 0)

  3. New Link Count (nlink)

    = 2

  4. What Happens

    = nlink = 2 — the inode and its data remain on disk; unlinking any single name never frees the data while nlink > 0.

  5. Data Deallocated?

    = No

  6. Disk Space Freed (MB)

    = 0.00

How it works

A hard link is a second directory entry (dentry) pointing to the same inode — not a copy. The inode's st_nlink field (visible via stat or ls -l) counts how many directory entries reference it. Deleting (unlinking) a filename only decrements nlink; the kernel frees the inode and its data blocks only when nlink reaches 0 and no process still holds the file open. This is why `rm` on a file with nlink > 1 doesn't free any disk space — the data is still reachable through the other names.

Formula

New link count

new_nlink = current_nlink ± delta (data freed only when new_nlink reaches 0)

n_cur
current nlink from stat
\Delta
links added or removed

Frequently Asked Questions

Why doesn't deleting a hard-linked file free disk space?

Because the file's data lives in the inode, not in the directory entry you deleted. As long as st_nlink stays above 0 — meaning at least one other name still points to that inode — the data blocks remain allocated and accessible through the remaining name(s).

Can I hard link across filesystems?

No. Hard links must reference an inode on the same filesystem/mount point, since inode numbers are only unique within a single filesystem. To 'link' across filesystems, use a symbolic link instead, which stores a path rather than an inode reference.

Why do directories always show at least 2 links?

A directory's own entry counts as one link, and its `.` self-reference counts as a second. Each subdirectory inside it adds another link via its `..` entry pointing back — so nlink on a directory reflects 2 plus its number of subdirectories, not files.