What is the difference between a hard link and a symbolic link ?
If you here you are maybe wondering what is the difference between them or just what is it , so today i will explain what is a hard link and how to create it, what is a soft link (symbolic link) and how to create it.
To starting, What is a hard link ?
A hard link is a mirror copy of the original file where is linked to, it works only for file and not directory, now you might wondering, what is the utility to do a copy of the original file when we have an another command to copy like “cp”. The utility to make a hard link is to had a copy where your hard link pointed to the original file, the hard link is a mirror of the original file so if you change the content of the original, the hard link will had the same changement, not as the command “cp” which is create only the copy and doesn’t take the changement of the original file, the hard link has the same inode number (which is the id created to the original file when it is created) as the original file where is pointed to, it has also the same permissions (the permission to execute, read or write the file) as the original file. And if we delete the content of the original file, the hard link is not affected and had the same content as the content of original file had (last changements).
To create a hard link, you just need to type this command:
“ln” is to create link and pointing on a file, by default is a hard link, the first argument is the original file that you wanted to create a hard link to, the second argument is the name of the Hard Link.
So now we know what is a Hard link, What is a Soft Link?
A Soft link or symbolic links is the same idea that a hard link but not the main usage, it will pointed to a file OR a folder (which is, the hard link couldn’t) not by his inode number but by his name, it has a different inode number. The soft link doesn’t contain the content of the original file, it has only the path of the original file, he is just something like a shortcut to this original file. So what happend, if i delete the original file ? If you delete the content or the original file, the soft link will not show the original content were the original file had, because is not a copy but just a link, it will not pointing on anything if the original file is deleted.
To create a soft link, you just need to type this command:
So now you know what is a hard link, a soft link and how to create it.