LinuxFilesystemHard Linkpnpm

Hard Links Explained: inode, Link Count, and pnpm Storage

Understand hard links through inodes, directory entries, link counts, deletion behavior, symlinks, filesystem limits, and why tools like pnpm use them to save disk space.

·Updated ·8 min read·Counting...
Hard Links Explained: inode, Link Count, and pnpm Storage

A hard link lets multiple filenames point to the same file data through the same inode. Creating a hard link does not copy file contents. It adds another directory entry that references the same underlying inode.

This is why hard links can save disk space and why tools such as pnpm can reuse package content efficiently.

What an inode is

An inode stores file metadata and pointers to file data: size, permissions, owner, timestamps, and where the data lives on disk. A filename is a directory entry that points to an inode.

When you create a hard link, the filesystem creates another filename pointing to the same inode.

Basic example

echo "hello" > original.txt
ln original.txt linked.txt
ls -li original.txt linked.txt

The -i option shows inode numbers. Both names should show the same inode.

If you edit one:

echo "updated" > linked.txt
cat original.txt

The other name sees the updated content because both names refer to the same file data.

Each inode has a link count. Deleting one filename removes one directory entry and decreases the count. The file data is removed only when the link count reaches zero and no process keeps it open.

That means:

rm original.txt
cat linked.txt

can still work because linked.txt still points to the inode.

  • Hard links share the same file content.
  • There is no meaningful "original" after links exist; both names are peers.
  • Deleting one link does not delete the data while another link remains.
  • Hard links normally cannot cross filesystem boundaries.
  • Hard links to directories are usually disallowed to avoid loops and complexity.
Feature Hard link Symbolic link
Points to inode / file data path string
Cross filesystem usually no yes
Directory support usually no yes
Target deletion other hard links still work symlink can become broken
Separate file no, another name for same inode yes, a small link file

Use symbolic links when you need a pointer to a path, especially across filesystems or for directories. Use hard links when multiple names should refer to the same file content on the same filesystem.

Traditional dependency installs can duplicate the same package across many projects. pnpm stores package content in a global content-addressable store and links it into projects, which can save disk space and speed up installs.

Conceptually:

global pnpm store/package-content
project-a/node_modules -> linked content
project-b/node_modules -> linked content

For practical pnpm usage, read pnpm in Practice: Installation, Migration, and Workspaces.

  • Efficient local package storage.
  • Backup systems that keep unchanged files without copying data.
  • Multiple names for the same file content within one filesystem.
  • Some deployment and cache strategies.

Do not use hard links as a substitute for version control, backups, or permission design. They are a filesystem mechanism with specific limits.

Subscribe to FreeMac

Weekly picks: free Mac software reviews, trusted source updates, alternatives, and low-friction guides.