What is the difference between hard link and symbolic link?
The inode contains the information about a file. It’s like a database. The information contains in the inode is the inode number, file size, owner of the file, permissions file, type file, number of links, etc.
In this case, we will talk about links.
Symbolic and hard links
To explain what is a symbolic link, we can use the shortcuts on windows, because they are both very similar. A symbolic link is another smaller file than the original file and they have a direct link.
Otherwise, a hard link is another file with a different name. They have both the same size and they are linked both with a link. The hard link is like a copy of the original file.
The differences between hard and symbolic links are:
Symbolic link is smaller than the original file. Hard link has the same size of the original file. If we delete or move the original file, the symbolic link will become useless. If the original file is deleted or moved, the hard link works normally.
To create a hard link we can make a example in the terminal
We have two directories dir1 and dir2
We create a file in dir1
We type some text into original_file and we use the command cat to show it
Now, we enter to dir2 and we create a hard link
After, we check the file inside dir2 and we can see the file has the same content of original_file
To create a symbolic link, we use the terminal to show the example. We use the previous directories to explain this concept
Inside dir1 is the file original_file and we will use that file to create a symbolic link. Then we enter to dir2 and we use the command ln -s
Now, with the command ls -l, we can see the symbolic link to original_file
Finally, if we use the command cat to see inside the file symbolic_link, we see the contain of the file original_file