Symbolic link and a hard link: the differences
Have you ever wondered about what’s the difference between a symbolic link and a hard link? Isn’t it the same thing? How is it different? What are they used for? What’s their purpose? Well, in this post we will solve these questions and also explain what’s the usage of both of them and the why they aren’t the same thing so let’s start from the biggening, shall we?
A symbolic link also known as soft link is basically a shortcut if you’re familiar with Windows, you should definitely know what a shortcut is but if you don’t, a shortcut acts a pointer or reference to an original file. For instance, let’s say you’ve got a file called A in a different folder but you want to have that file in the current folder you’re currently working on. Normally you’d have to go all the way back to that folder if you need to access information from that particular file A but if you’ve got a shortcut to file or its folder you can easily get access to it without having to go back and fort in order to work with it. But please notice, if you delete, move it somewhere or even rename the original file, your symbolic link, shortcut or soft link (you name it) becomes useless as it will be pointing to a file that doesn’t longer exist.
But Jimmy, how can I create it?
To create a symbolic link all you need to do is to use the following command:
ln -s typeTheOriginalFileNameHere TypeTheShorcutName
First of all, and as it was described above you need to enter ln followed by the original file name and the shortcut name in your console and that’s basically it. Wait, is it that simple? Yup.
A hard link is a directory entry that associates a name with a file on the system. All directories-based system has one hard link given to each file and also a name. Therefore, creating a hard link has the effect of giving a file multiple names. For instance, if you create a hard link for a particular file, this folder or file could have different names. But in fewer words, it’s a mirrored copy of the selected file that has the ability to access the data available in the original file.
But Jimmy, how can I create a hard link?
To create a hard link all you need to do is to use the following command:
ln typeTheOriginalFileNameHere TypeTheHardLinkName
The differences between them
First of all, if you’ve noticed it above, both of them are pretty much alike so how can you notice the difference between them? Well, there are a couple of things you should bare in mind so that you get to know the difference.
· A symbolic link creates a connection to the file itself, not to its memory. That’s why we also call it shortcut as it’s pretty much so. A shortcut to the original file.
· A hard link creates a connection to the address of a particular file which is usually created on the system memory and normally it isn’t viewable by the user. This is why when you create a hard link its size is greater than a soft link. Pretty straight forward, isn’t it?
· Bare in mind that when you delete a hard link, you’re likely to get an error as this file shouldn’t be deleted (in most cases) but if it’s something that doesn’t affect the system, you should be good to go.
· Permissions: usually when you create a hard link, it’s likely to get the same permissions that the original file has got because as you already know, you’re creating a mirrored copy of that file whereas a symbolic link will have different permissions.