Hard and Symbolic Links on Linux. What is the difference between this two types of links?

Miguel Pacheco
3 min readFeb 3, 2021

Hello and welcome to my first blog here in Medium, today i’m going to explain Hard and Symbolic Links on Linux but first we need to know what each one is, so. Let’s go.

First we need to know some information related to this.

What is a link?

In Linux, a link is a connection between a file name and the actual data on the disk.

What is a inode?

inode or Index node is information contained within a Unix System (Linux) that contains details about each file (a file is an object on a computer that stores information such as owner, location of file, etc.).

Example of a inode:

Now that we know what is a link and a inode we can know what is a hard link and a symbolic link, and how to create it

What is a hard link?

Hard links are a links which the system uses to create elements of the file system itself, for example files and directories (directories are the locations for storing files on your computer.).

How to create a Hard link?

For create a Hard Link we need to run the next command in our terminal (A terminal allow us to acomplish and automate tasks without the use of a Graphical User Interface (also known as GUI).

ln {OriginalFile}{HardLink} (Where OriginalFile is an existing file and HardLink is the file that will connect by the hard link)For example:
ln {OriginalFile}{HardLink}

Well… now we know what are hard links, but what are symbolic links (also known as soft links)

What is a Symbolic Link?

A symbolic link is a file pointing to another file, connecting with another file. So if the original file is deleted, the symbolic link would have an error, Also they have a smaller size than a hard link file.

How to create a Symbolic link?

For create a symbolic link we need to run the next command:

ln -s {OriginalFile}{SymbolicLink} (Where OriginalFile is an existing file and SymbolicLink is the file that will connect by a symbolic link)(using -s we indicate that the link to create we will to be a soft(symbolic) linkFor example:
ln -s {OriginalFile}{SymbolicLink}
Example of how to create a symbolic link:
ln -s /bin/ls __ls__

Differences between hard and symbolic (also known as soft) links

Now that we know that what are Hard and Symbolic link and how to generate it, we need to know what are the differences between this types of links in linux.

  • A symbolic link (or soft link) is a link to another name in the file system meanwhile a hard link is a link to the inode (see inode at the top of the document).
  • A hard link has been made the link to the inode. Deleting, renaming, etc. the original file will not affect the hard link, nevertheless, if you delete a file and has a symbolic link, the symbolic link would have and error.

--

--

Miguel Pacheco

 User | Student at @HolbertonUru | Aspiring to be a Web developer at @Apple