Symbolic link, Hard link in Linux

Joudirim
3 min readFeb 2, 2021

--

Introduction

Hello, in this blog we are going to talk about Symbolic links (Soft links), Hard links and the difference between them.

Difference between Hard link and Soft link

What is a Symbolic Link ?

Symbolic Links, also known as symlinks, are file-system objects that point toward another file or folder.

Symbolic link

These links act as shortcuts with advanced properties that allow access to files from locations other than their original place in the folder hierarchy by providing operating systems with instructions on where the “target” file can be found.

What is a Hard Link ?

Hard link

A hard link is a link that directly associates a name with a given file in an operating system.

Unlike a soft link, which changes the pointer when the file is renamed, a hard link still points to the underlying file even if the file name changes.

What is an Inode ?

An inode is a data structure that contains a pointer to the location of the data, as well as some other pieces of metadata.

Files can have multiple names. If multiple names hard link to the same inode then the names are equivalent; i.e., the first to be created has no special status. This is unlike symbolic links, which depend on the original name, not the inode (number).

An inode may have no links. An unlinked file is removed from disk, and its resources are freed for reallocation but deletion must wait until all processes that have opened it finish accessing it. This includes executable files which are implicitly held open by the processes executing them.

What is the difference between Symbolic link and Hard link ?

Soft link and Hard link comparaison

A symbolic or soft link is an actual link to the original file, whereas a hard link is a mirror copy of the original file.

If you delete the original file, the soft link has no value, because it points to a non-existent file.

But in the case of hard link, it is entirely opposite. Even if you delete the original file, the hard link will still has the data of the original file. Because hard link acts as a mirror copy of the original file.

How to create Symbolic link ?

ln is a command-line utility for creating links between files.

To create a symbolic link is Linux use the lncommand with the -s option:

Create a Soft Link to myfile.txt:

ln -s myfile.txt myfile_softlink.txt

How to create Hard link ?

To create a hard link in Linux use the lncommand. By default, the ln command creates hard links.

Create a Hard Link to myfile.txt:

ln myfile.txt myfile_hardlink.txt

--

--

Joudirim
Joudirim

Written by Joudirim

Holbertonschool software engineering student

No responses yet