Soft and Hard Links

Kashif Ali
A free video tutorial from Kashif Ali
Professional system administrator and consultant.
4.5 instructor rating • 2 courses • 30,348 students

Learn more from the full course

Learn Linux administration and linux command line skills

Learn Linux administration and Linux command Line skills from scratch. Great for both beginners and Advanced Learners.

30:15:10 of on-demand video • Updated January 2020

  • Become a professional Linux administrator and be able to apply for Linux jobs
  • Gain advance Linux systems administration skills and have deep understanding of Linux fundamentals and concepts
  • Be able to create, support and manage Linux servers in a Corporate environment
  • Be able to better troubleshoot servers and get started with automating tasks
  • Design on your own career path from scratch as a Linux Professional
English [Auto] In this lecture we will learn about soft and hard links. But before we move on to soft and hard links you need to know what and I know it is. I know it stands for an index node. Each file at the time of creation has many attributes assigned to it such as files type size permissions owners name group name access control list links and other related info known as metadata. This metadata info takes only hundred and twenty eight bytes of space and this tiny storage space is known as an AI node or an index node. I know the signs a numeric identifier to each file which is used by the kernel. So for example if you look at this example this is showing you the rights of a file. For example the name of the file the permissions assigned to a particular file. Who is the user who is the group. When was the file created. All this information is known as the metadata. This is the metadata of a file. That's how your kernel understands what this file is. The metadata is then saved as an eye node so there's a small tiny storage space. It is known as an AI node or an index node I know then assigns and numeric identifier to each file which is used by the kernel. You can probably say that a file really is the AI node and names that are attached to this AI node to make it easier for humans to work with them. So when you look at a file you will see like a file name as for example file one but your kernel understands the file one as a numeric identifier number which is known as an AI node let's start with what a link is. A link can be compared to a shortcut. It's basically a pointer to another file in Linux. Two different kinds of links are supported. The hard link and the symbolic link also known as the soft link. Let's start with the soft link soft link is also known as assembling or symbolic link. Soft link is similar to a shortcut in windows. They point to another file if the original file is deleted simply becomes useless at as it is a shortcut to a file that does not exist anymore. Let's look at an example. We will create a soft link to file one and we will name it something maybe file two and then we will do an LLC and look at some of the rights and I'll show you how it looks like how you can identify a soft link and we will also create a softening. We will also look at the AI node and how to find and I know of a file so let me open up the terminal and let's look at these examples through the terminal. So currently I have a file called file 1. Let's create a link to this file to create a link. We'll type in the command n it stands for link and if we type in a high finish that means a shortcut to file one and then the shortcut will be called file to hit enter. Let's do a little or less minus all you can do. It's the same thing. And look at file to know if you look at file two on the right side. You will see file 2 and there's an arrow. It means file 2 is actually a link to file 1 and if you look at that on the left side where you see the permissions there's a editor before it. That means there's a soft link there. When you create a soft link do a little or less minus so you will see it listed here. When you see that that means there's a soft link there and a showing there is one link right here attached to this file that link is pointing to file 1 so file two as a shortcut to file one. And that's a soft link now to find the I know the full file. You can run parallel with a minus AI option and name of the file file to hit enter now all the information is still the same except that it also added another column and this is the I know number of this file so that's how you can find an AI node number and that's how you can create a soft link. Now let's look at a hard link Harling associates one or more files with a single line node number unlike a soft link. This also implies that any changes made to original file will also be applied to the hard linked file for example to create a hard link to a file. You just type in L.A. and then the file name and then the name of the shortcut that you're creating or the hard link that you're creating. So let me bring up the terminal and let's look at this example. So let's create a let me do an atlas first as you can see we have a file one and we have a soft link to file one called file 2. And before we move on let me show you one more thing. Let's do an alone minus AI and let's do it to both files. One thing I wanted to show you was when you create a soft link it gets a completely different I know number than the original file. As you can see right here that's the file ones I know number. And here that's the file 2s. I know number when we create a hard link hard link does not get a new AI node number. It will be the same I node number as the file 1. So let's look at that example. Let me clear the screen and let's create a hard link first to file one to create a hard link. You don't need to type in any options you're just typing Ellen and then the file name file is file 1. Now re creating a hard link to file one called file 3 hit enter and the command executed successfully. Now let's look at a low minus AI to check the AI node number of File 1. Okay so that's our original file. One thing you will notice here here it says 2 so it has 2 links to it. Now let's do an El Al on the newly link that we created which is file 3. So if I hit a enter here as you can see right here is the I note for file 1. And right here is the AI node for file 3. The both of the links are the same. So if one file is deleted the other file will still exist. Unlike assembling when you delete a soft link shortcut becomes pretty much useless. There is also one more thing that you should understand is whenever possible you should create a hard link not a soft link because hard links are much faster and they reside on the system. However soft links can be created anywhere. Soft link can point to any computer to a file somewhere else anywhere in the world so hard link can only be on the same system. That's what hard links are faster and whenever possible you should think of creating the hard links not the soft links.