concepts

Inode — File Identity and Metadata

An inode represents filesystem object metadata: type, permissions, owner, timestamps, size and link count. A directory entry supplies a name; several hard links may name one inode on the same filesystem. A symlink instead has its own inode and contains a target pathname. Compare the device/inode pair to identify an object within the current view; inode numbers may be reused after removal, and remote/overlay filesystems can have special identity behavior. Unlink removes a name; an open file may remain usable until its remaining references disappear. Do not infer available bytes merely from link count or logical size; sparse files, compression and snapshots affect allocation. The example creates a hard link and a symlink to a tiny private file, checks metadata, then removes the original name. It never modifies existing files. Example prerequisites: Linux, Bash and Python 3 standard library; run as a non-root user in a private temporary working directory. Example scope: native userspace observation. Expected output: hard link survives; symbolic link is dangling. No system configuration changes.

Formal Syntax & Structure

linux syntaxlinux
stat PATH; stat -c "%d:%i %h" PATH

Parameters & Attributes

NameTypeDescription
st_devdevice identifierFilesystem identity as exposed by stat.
st_inoinode numberObject number within that filesystem.
st_nlinkintegerNumber of hard links.

Return Value

Concept / observation

stat returns metadata or reports a failure; the example prints normalized link and identity checks.

Working Example

Example Snippetlinux
python3 - <<'PY'import os, tempfilefrom pathlib import Pathwith tempfile.TemporaryDirectory() as d:    p, h, s = [Path(d)/n for n in ('a','hard','sym')]    p.write_text('hello')    os.link(p,h)    s.symlink_to('a')    a,b,c = p.stat(),h.stat(),s.lstat()    assert (a.st_dev,a.st_ino)==(b.st_dev,b.st_ino)    assert a.st_nlink==2 and c.st_ino!=a.st_ino    p.unlink()    assert h.stat().st_nlink==1 and h.read_text()=='hello'    assert s.is_symlink() and not s.exists()print('hard link survives; symbolic link is dangling')PY
Linux Reference