Intro to hard links and symbolic links

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

Mon Jul 15 2019 - 2 min read

The first thing to do is to define what are hard links and symbolic links. With this knowledge it’s going to be easy to understand their difference and why it is important to know it.

A symbolic link, also known as soft link, is a link to the original file, in other words is a special kind of file that points to another file, similar to a shortcut. So it simply points to another entry somewhere in the file system.

A hard link is an additional name for an existing file, in other words hard links refer to the specific location of physical data. It is essentially a label or name assigned to a file.

In order to create a symbolic link with ln command you can type

ln -s source new_soft_link

ls -ali source new_soft_link

To create a hard link with ln command you can type

ln source new_hard_link

ls -ali source new_hard_link

When you use the -i flag it list all files with inode.

Inode is a data structure in a Unix-style file system which describes a filesystem object such as a file or a directory. Each inode stores the attributes nd disk block locations of the object data.

Directories are lists of names assigned to inode.

What is the difference

Links diagram explaining the difference

These seems to be the most important differences, the best way to understand it is to try all by yourself and see how the inodes are the same or different, depending on the link use it and how they behave if you delete the original file.

Regresar

Enjoy this note? Feel free to share!

X logo Y Combinator logo LinkedIn logo