Hard link and symbolic link in Linux

Daniel V.
3 min readJun 8, 2020

Links allow us to access files or folders more easily, without the need to scroll through the entire directory hierarchy

For example if we frequently access to the folder:

/usr/share/wordlist/wfuzz/general/

we would have to use the command

cd /usr/share/wordlist/wfuzz/general/

every time, so it is much more comfortable to create a link in our home that points to that directory, so all you have to do is use the command:

cd name_of_link

So… How do I create the links?

First you need to know that there are two types of link, hard links and symbolic links

Hard links:

A file can have several names, so the physical link is one more name for a file in another location. The file will only be removed from disk when the last existing name has been removed. The file will always be the same in all locations where a physical link has been created. One aspect to keep in mind is that physical links can only be created for files and not directories.

To create a hard link we will use the following syntax:

ln [origin] [name of the link]

for example to create a hard link in our current work directory of the file http_methods.txt locate in /usr/share/wordlist/wfuzz/general/ we need to type:

Img 1. Hard link

Symbolic links

To create a symbolic link we will use the following syntax:

ln -s [origin] [name of the link]

It is the same syntax that we use for the physical link only that we add the -s option to indicate that we want to create a symbolic link, for example to create a symbolic link in our current work directory of the file http_methods.txt locate in /usr/share/wordlist/wfuzz/general/ we need to type:

Img 2. Symbolic link

So… What differences are between hard link and symbolic links?

  • Symbolic links can be made with files and directories while hard links can only be done between files.
  • Symbolic links can be made between different file systems, hard ones cannot.
  • Hard links share the inode number, symbolic ones do not.
  • In symbolic links if the original file or directory is deleted, the information is lost, in hard ones it is not.
  • Hard links are exact copies of the file while symbolic links are mere pointers or “shortcuts”.

Before finishing we must clarify a term. “inode”, So:

An INODE is a data structure, so to speak, a table that contains information about a file.

Each file is identified by an inode number. This number is unique within the entire filesystem.

Within each inode there is the following information:

  • Inode number
  • File type
  • Owner of said file
  • File permissions
  • Date of creation of the same

And that’s it, thanks for reading and I hope you have learned something new!.

--

--