{
  "slug": "link-count",
  "term": "Link count",
  "aliases": [
    "hard-link count",
    "st_nlink",
    "stx_nlink"
  ],
  "definition": "A link count is filesystem metadata reporting the number of hard links to an object, subject to filesystem-specific counting conventions.",
  "note": "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. [link-count-inode]\n\nLifetime: 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. [link-count-unlink]\n\nObservation: 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. [link-count-stat]\n\nDirectories: 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. [link-count-ext4]",
  "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."
  ],
  "related": [
    "hard-link",
    "inode",
    "unlink",
    "directory"
  ],
  "status": "shipping",
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-15",
  "citations": [
    {
      "id": "link-count-inode",
      "title": "Linux man-pages: inode(7), hard-link count fields",
      "url": "https://man7.org/linux/man-pages/man7/inode.7.html",
      "accessed": "2026-11-15"
    },
    {
      "id": "link-count-unlink",
      "title": "Linux man-pages: unlink(2), last link and open-file lifetime",
      "url": "https://man7.org/linux/man-pages/man2/unlink.2.html",
      "accessed": "2026-11-15"
    },
    {
      "id": "link-count-stat",
      "title": "Linux man-pages: stat(2), object selection and observation timing",
      "url": "https://man7.org/linux/man-pages/man2/stat.2.html",
      "accessed": "2026-11-15"
    },
    {
      "id": "link-count-ext4",
      "title": "Linux ext4 documentation: Index Nodes, i_links_count and DIR_NLINK",
      "url": "https://www.kernel.org/doc/html/latest/filesystems/ext4/inodes.html",
      "accessed": "2026-11-15"
    }
  ],
  "provenance": [
    "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"
  ]
}
