Hard Link/Symbolic Link

Renzo Perez
2 min readFeb 3, 2021

--

In Linux each file and/or directory has assigned a integer called Inode. The inode is unique for each file and/or directory.

In each inode there is info of different attributes like owner, location on the hard disk.

A Hard Link is new pointer that points to the same place of the hard disk in which it points the the pointer of the original file, so the original files and the hard links had the same inode.

A Soft Link pointS the original file, not the inode, like a File Shortcut in Windows, so the soft link will have a diferent inode than the original file

So What happens if we erase our Original File?

The link of the Symbolic its not erased but the link to the original file gets broken, but the hard link will still have the same content as the original file

Show me the way

To create a Hard Link we use the command (ln)

ln [File_name] [Hard_link_name]

To create a Soft Link we use the command (ln — s)

ln -s [File_name] [Symbolic_link_name]

An example

So lets say we create our original file Skynet

touch Skynet

Just write any message inside Skynet file

We can create a Symbolic Link called T_800 linked to Skynet like this

ln -s Skynet T_800

We can create a Hard Link called Genisys like this

ln Skynet Genisys

If we delete the file Skynet, we still can access to its data with the Genisys file

if we remove the file Skynet, we wont be able to access to the Skynet data with the file T_800

Now try it yourself

--

--