Links In Linux

Links In Linux

Inodes, Hard Links, Soft Links, Partitions, Data Recovery.

Everything's a file in GNU/Linux. Even the directories are also treated as files. To understand Links In Linux it's important to learn about how Linux system stores its files.


Inode is a data structure in Unix style file system that describes a file system object such as a file or a directory. Every file has an entry with a filename and an Inode. An inode stores all the information about files, except the actual data which is written on the disk and the filename.

To access Inodes, type ls command with i flag included.


The numbers on the left-hand side are inodes. When partitions are created in a Linux file system, a specific number of Inodes are also created for that partition. Ideally, there would be a sufficient number of Inodes for all the files that shall be created in that partition. In extreme cases (which is more unlikely to happen), Inodes might get exhausted; in that case, no other files could be created.

Hard Link

Hard Link is a directory entry that associates a name with a file. For Hard Links, Inode numbers would be the same, and the file size would be the same as well because it gets the data from the same file. So it means we can't edit both files(the original file and the linked file) at the same time.

To create Hard Links, use ln command. Here the sample file name is 'a'.



The images show the creation of Hard Link. In the second image, the yellow box shows the number of links associated with the files.

To unlink the file, just type unlink a_hard_link


Achilles' Heel Of Hard Link

To create a Hard Link, the file has to be in the same partition. Cross partition linking is not possible. And there is a good reason for this; when a partition is set up on a file system, it sets up Inode numbers in the same partition, so the chances are, the other partition might also have the same Inode number. This could lead to conflict and as a result, it might create some sort of continuous system loop.

To create cross partition links, or for general purposes, Soft Links or Symbolic Links could be used.

Soft Link

Soft Links contain a reference to another file or directory in the form of an absolute or relative path. To create Soft Link, use ln command with s flag.


In the above image, a file Soft Link has been created for a file named b. As it's evident the Inode numbers are different. The arrow pointing towards b shows the number of characters in the file name.

If file b is renamed, the Soft Link would break.



Role Of Inodes In Data Recovery

Inodes play an important role in referencing data points. As aforementioned, if the Inode numbers get exhausted, even with a large amount of disk space, files cannot be created. If we remove or unlink an Inode, it simply means that data is still present on the disk, unless and until it is overwritten, and that data could be recovered.