Hard link and Symbolic link : What are they ?
Hard links and Symbolic links are used as pointers to the files, referring to what (content, permissions, etc…) and where (location of the file) it is.
What is the difference between those two ?
Those are two differents way of doing, as seen above in the picture, we will talk what’s specific about each other and how to create it.
- The Hard link is a direct link to the content of the source file, it is like a mirror, it depend not of the source file existence, for example, even if the original file is removed, the hard link will still be effective. It can’t be linked to a directory and is valid only in the same file system. As it’s link is direct, it shares the same permissions as the source file.
But why another way of making a link ? Here some more informations about it.
- The Symbolic link is not a direct link at the opposite of the hard link. It refers to the name of the source file and it is dependent of it, as the symbolic link will become useless without it’s referring file. Doesn’t link to the content of the source file but free of crossing file system boundaries and can possess different permissions than the original file.
How to create them ?
Here a little example to illustrate the process of making a Hard link, in it we will use “source.file” as file example. The command to create a it is quite simple :
ln source.file hlink.file
The ln is the command used to build the link, the source.file is the referred file, and the hlink.file is the newly created hardlink.
To make a symbolic link, we use the same command but we will need an option to specify which link type we want, again we use our “source.file”.
ln -s source.file slink.file
The addition is the option -s which specified that we want to create a symbolic link for our source.file. As reminder it is linked to the name of the file and not it’s content itself.