Member-only story

Linux — Hard Links Introduction

Tony
5 min readDec 8, 2023

What is Hard Link

In Linux, a hard link is merely an additional name for an existing file on Linux or other Unix-like operating systems. Any number of hard links, and thus any number of names, can be created for any file. Hard links can also be created to other hard links. However, they cannot be created for directories, and they cannot cross filesystem boundaries or span across partitions.

An example of hard links looks like:


$ echo "Hello, World!" > file1.txt
$ ln file1.txt link1.txt
$ ls -li
1234567 -rw-r - r - 2 user group 14 Jan 1 00:00 file1.txt
1234567 -rw-r - r - 2 user group 14 Jan 1 00:00 link1.txt

Now let’s try to modify the original file:

$ echo “How are you?” >> file1.txt
$ cat link1.txt
Hello, World!
How are you?

A hard link is essentially a directory entry, or pointer, to a file’s data on the storage device. Unlike a shortcut or a symbolic link, which contain a path to another file, a hard link is indistinguishable from the original file. This is because both the original file and the hard link point to the same inode — the filesystem’s internal representation of a file.

Since a hard link points directly to the data, it always refers to the source, even if the original file is moved or deleted. As long as there…

--

--

Tony
Tony

Responses (2)