What is the difference between a hard link and a symbolic link?

Erika Osorio Guerrero
2 min readMay 5, 2020

--

In Unix-like operating systems such as Linux, “everything is a file” and a file is fundamentally a link to an inode (a data structure that stores everything about a file, apart from its name and actual content).

So a symbolic link its an actual link to the original filename in the filesystem so if you delete the file, the link will not work anymore, because that file doesn’t exist.

In the other hand Hard link is exactly a copy of the original file, and if you modified the original one, the copy will change too like the original; but what happens with the link if you delete the original file? Well you still can be linked to the file but this will be the copy file, which had the same information as the original one.

How to create a Symbolic link

  1. create a Directory
$ mkdir test

2. change the directory you just create

$ cd test

3. Now create a new file with some data on it

$ echo "Welcome to Holberton" >source.file

4. Let us view the data of the source.file.

$ cat source.file
Welcome to Holberton

Well, the source.file has been created.

5. Now, create the a symbolic or soft link to the source.file. To do so, run:

$ ln -s source.file softlink.file

So comparing the data of the soft link and the file

$ cat source.file 
Welcome to Holberton
$ cat softlink.file
Welcome to Holberton

and what is the difference between the two. Use examples to illustrate.

How to create a Hard link

  1. create a Directory $ mkdir dirname
$ mkdir test

2. change the directory you just create

$ cd test

3. Now create a new file with some data on it

$ echo "Welcome to Holberton" >source.file

4. Let us view the data of the source.file.

$ cat source.file
Welcome to Holberton

Well, the source.file has been created.

5. Now, create the hard link to the source.file. To do so, run:

$ ln source.file hardlink.file

What is the difference Between Hard and Symbolic Link

--

--