Hard Link Count Calculator
Track hard link counts and their effect on inode reference counting and deletion.
About Hard Link Count Calculator
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
Worked example
With the default values below, Hard Link Count Calculator returns New Link Count (nlink) of 2. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Current stat nlink Valueminimum 1
- 1
- Operationone of Create additional hard link(s), Remove hard link(s)
- Create additional hard link(s)
- Number of Links to Add/Removeminimum 1
- 1
- File Data Size (MB)minimum 0
- 100
Results
- 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
- 1Values used
- 2New link count
- 3New Link Count (nlink)= 2
- 4What Happens= nlink = 2 — the inode and its data remain on disk; unlinking any single name never frees the data while nlink > 0.
- 5Data Deallocated?= No
- 6Disk Space Freed (MB)= 0.00
Assumptions and limits
- The result is derived only from the 4 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to 2 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
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.
