All guides
Home Glossary Hard link
Term

Hard link

A hard link is a directory entry that associates a name with a specific inode on a filesystem, allowing multiple names to point to the same physical data.

A hard link is a directory entry that maps a filename directly to a specific inode number on a filesystem. In Unix-like operating systems, a file's content and metadata reside within an inode, while a filename is simply an alias pointing to that target ID. Because every hard link references the exact same underlying structure, the operating system treats all hard links to a file as identical, co-equal entry points.

How it works

When you create a hard link, the filesystem registers a new directory record pointing to an existing inode and increments that inode's reference counter by one. The physical data blocks on disk remain untouched, and no extra storage is consumed for file content. The operating system tracks the active reference count; only when every hard link is deleted—bringing the reference count down to zero—does the filesystem mark the data blocks as free space and deallocate the inode.

Because `inode` indexing is unique to individual filesystems and storage volumes, hard links cannot cross partition boundaries or mount points. Furthermore, modern Linux kernels explicitly prevent non-root users from creating hard links to directories. This safety constraint prevents circular references and infinite recursion loops during tree traversals.

Example

You can create and inspect hard links on Linux using standard shell utilities like ln and ls. Below is a simple workflow demonstrating hard link creation, shared inode verification, and link count tracking:

# Create a sample file
echo "Server Config Data" > original.conf

# Create a hard link named backup.conf
ln original.conf backup.conf

# Inspect inode numbers and link counts
ls -li *.conf
# Output:
# 1048578 -rw-r--r-- 2 user group 19 Nov 14 15:00 backup.conf
# 1048578 -rw-r--r-- 2 user group 19 Nov 14 15:00 original.conf

Both files share the identical inode index (1048578) and display a link count of 2. Editing backup.conf immediately updates original.conf, as both filenames address the exact same bytes on disk.

What matters when choosing a server or hosting

When managing server storage, hard links offer a zero-overhead method for duplicating access paths to large datasets. They play an integral role in building an efficient VPS Backup Strategy 3-2-1. Backup utilities like rsync rely on hard links to generate incremental snapshot builds: unmodified files are linked to prior runs, giving each snapshot the structure of a complete backup while saving disk space.

However, hard links demand planning when designing application delivery environments, such as a custom Systemd for Telegram Bots deploy process or a VLESS Reality Setup Guide infrastructure. If your deployment pipeline relies on fast file swaps or container mounts across isolated virtual block devices or network shares, hard links will fail if source and destination paths reside on separate filesystem partitions.

Common mistakes

  • Confusing hard links with symbolic links: Symlinks store a target path string and can break if the original file moves; hard links point straight to the inode and remain valid even if the original filename is renamed or deleted.
  • Trying to link across filesystems: Attempting to create a hard link between two different mount points (such as /var and a separate storage volume) triggers an invalid cross-device link error.
  • Expecting isolated edits: Modifying file permissions or content through one hard link changes the shared inode, altering the file for all associated names.

FAQ

Does deleting the original file erase the data?

No. Deleting a file via rm unlinks that single directory entry and decrements the inode reference count. As long as at least one other hard link points to the inode, the underlying data remains fully intact and accessible.

Do hard links take up extra disk space?

Hard links consume virtually no additional disk space. They only create a small directory entry pointing to an existing inode, leaving the underlying data blocks untouched.

On Unix systems, every standard file is technically a hard link with a link count of at least one. You can view a file's total reference count using ls -l or inspect its inode number with stat.

All glossary terms

Glossary

Related terms

Full glossary

New guides every week.

A digest of the best pieces on servers, VPN and self-hosted software. No ads, no spam.

1 email a weekOne-click unsubscribeRU · EN
Only slipjar.app articles, nothing else.