Link count
A link count is filesystem metadata reporting the number of hard links to an object, subject to filesystem-specific counting conventions.
Meaning: Linux exposes the hard-link count as st_nlink in stat results and stx_nlink in statx results. It counts links, not processes, open descriptors or independent copies. The count does not identify the names that refer to the file. [1]
Lifetime: For ordinary local Linux files, removing the final hard link can leave an open file usable through an existing descriptor. A zero link count therefore does not establish that the file is no longer in use, that its blocks have been reclaimed or that its data has been securely erased. Network-filesystem behavior needs separate qualification. [2]
Observation: stat() follows a final symbolic link, whereas lstat() reports the link object itself; fstat() reports the object selected by a descriptor. Choose the object before comparing counts. Linux also warns that different stat fields can describe different moments during a call. A multi-file inventory needs its own consistency boundary; matching counts alone cannot identify matching hard-link groups. [3]
Directories: Do not treat the link count as a portable count of child entries. The ext4 on-disk documentation describes DIR_NLINK using i_links_count = 1 when the directory's hard-link count is not known. This is a directory-count convention, not evidence that a regular file has only one name. [4]
Relations
Advantages
- Helps describe namespace linkage when the filesystem supplies an exact count and the observation scope is controlled.
Limitations
- Equal link counts do not prove equal hard-link relationships or independent backups.
- A count does not enumerate names or measure open references; directory conventions can differ from regular-file counting.
Citations
- Linux man-pages: inode(7), hard-link count fields
- Linux man-pages: unlink(2), last link and open-file lifetime
- Linux man-pages: stat(2), object selection and observation timing
- Linux ext4 documentation: Index Nodes, i_links_count and DIR_NLINK
Sources & caveats
- Primary-source synthesis of Linux man-pages and ext4 format documentation; no new filesystem, recovery or large-directory experiment was performed.
- The inventory and backup-acceptance guidance is an engineering inference, not a claim that stat provides an atomic snapshot.
- Human context: https://hesela.com/analyses/backup-verification-is-not-a-restore-test/#link-count-observation