Soft links and hard links this is one of the important topics in Linux and something that you will have
to remember because you would be working on creating saaf links and hard links and your learnings career.
Or if you're going to be working in System Administration capacity before I tell you anything about
what a soft link and hardlink is I have to tell you I know what I know is I know is basically a pointer
or a number of a file on a hard disk.
So if I create a file called let's say Hokke that file name is H U L K that is a name for me as a human
for me to understand the name of the file.
But computer does not understand names computer understand numbers.
So every time we create a file computer assigns a number to that file on a hard disk and associate that
number to it that number is called i node.
And every time we try to retrieve their file or read that file it goes.
Andrew Creve that number.
So now now you know.
I know.
Let me tell you about a soft link.
Now a soft link is a link that when created and it will be removed if a file is removed or renamed.
So if I create a file and I link create a link a soft link to that file.
So once I create that it actually looks for that I know through their files so that creates a soft link
so if I remove the source file it will remove the destination link where as hardlink is venta leading
or renaming the source file the hardlink will not change.
It will remain the same as if you have copied it to create a hard link command you will run.
And as a link to create a soft link you will run the same command but with the option minus S and I
have a picture right here which of course a picture speaks a thousand words.
So if you see on the right hand side it's my soft link.
It is connecting through my file to the i node where as my hardlink is connecting straight to the heart.
I know.
So if the middle part which is my file that text goes away my soft link goes away.
However in my hardlink file if middle file my file that text goes away it doesn't matter.
No files stays.
Let's get that log into our machine.
A Linux machine and I will explain you much better how those links work.
By the way one more thing I should mention.
Link is just like a shortcut in a regular term as if you are creating a shortcut on your desktop in
your Windows environment.
You have a file located somewhere in Windows system 32 blah blah blah blah.
Of course you have to go to that file all the time by navigating through their file system.
Click click click click click click click click.
So much word.
Man.
So what do we do.
We create a shortcut to our desktop.
All you have to do is double click and bombing runs the same.
Just like that we have Linux softening and hardlink.
So without further ado I'm going to log into my machine and I'll explain you.
This is our machine is going to drag a little more to the left.
Just wanted to confirm again.
I am logged in as myself.
This is my name this is my home directory.
Perfect.
I want to create a file called Hope everybody knows what great fun character.
Big giant character like like his movies.
OK anyway I created a file called Hulk.
Now I will like to create a link to that file Hulk.
I will go to temp directory I'm in temp.
Not in my home directory and I want to create link soft link to Hulk and Hulk file location his home
I saw and the name of the files Hoque but it created the file link.
How do we verify your friendly command.
Alas my SL TR.
And if you see what the bottom is telling you it has created a link and Linux operating system since
we are running Linux with the Goines changes some of the color changes to blue.
So right here the first bit it's telling you it is.
L What is L for L is for Lenk.
What is D for D is for directory s.
Very good.
And what is a file that does not have anything.
Of course it's a file.
I already answered that.
OK anyway.
So it created a link.
Now I will go back to my home directory by just typing C D PWT to just confirm I am in my home drapey
as I am and I will type something in my file called Hauk so I'll do echo and do homework is super hero.
OK.
And we'll put that to poke fun.
When I do cat Hulk it's there.
Right.
OK now I'm going to go to my temp directory and I'll do cat this confirm I'm in my temporary years and
I'm going to cat the Hulk.
And you say it has the same content that I just typed in so it's just a short cut just a link.
Oh we'll come back to my home directory and I will run LS minus L.
What is I.
Stands for.
I know it's if I wanted to find out the I know of this file I would run I.
So yeah it's there.
But since I didn't type LS myself TR had went into middle's whole time I lost myself.
And then I.
So this way it will be at the bottom.
If you see that I node number right here is the number that is associated with my file Hoque gain I
note is the numbers that are or is remembered by your operating system and it is on your desk.
It doesn't remember Hulk.
When I go to temp and do ls myself here and right here if I do it myself he or I need to find out the
I know of this hulk.
It has a different I.A..
Is it a different.
I'm not sure.
Let's check.
He TR I and I'm going to home.
So park it has a different.
I know.
So this one is remembered as a different file.
It is remembering and it's a link.
It does not know that it is actually a file.
It just knows there is a link so this number is associated to a link.
Now I will go to my home directory again and this time I'm going to remove the Hulk.
Hulk is gone from my home directory.
Right.
I'm going to go back to temp directory and I'm going to see where my Hulk is by if I just type Haug.
Just give me hope.
There you go.
So Hulk is there but it's no longer blue or it's look crooked why looks crooked.
Because the file is gone.
If I do cat right now and do a dog tell me what will happen.
No such file or directory.
Of course there is no such file because the link is removed.
The source link is removed so the link will still linger around even though the source of the link is
not there.
So better I'll just remove the link as well and just verified Yep it's gone.
If I just want to do it myself.
You're just too hot.
Sinopah.
So that's how the soft link works.
Now I will explain to you how the hardlink works.
Let's go and create our file again or call it Hawke again and I will put something inside the file.
Echo Park is a super hero.
OK I'll put that in hock.
I do have verified just to catch the file.
And yes Hulk is a super hero.
The continents there.
Now I will go into temp directory and I want to link to this file creating hardlink.
You see I'm not going with minus as option S stands for snaffling so I'll do Lanc home.
I have Zaal Hawk link is created how do we verify it.
We just run a last minute sell TR and you will see at the bottom.
It's telling me that the link is created.
Now the difference between this link hardlink and the soft link is that there is no pointing to other
file that is the difference of hardlink softly.
Now if you read if I read the content of this file it says Haug is a superhero it's the same content
everything the same.
Now let me go back to my home directory.
I'm in the home directory.
Let's check that help file and I will write down something else in it.
Now go one two three and then two Haak.
That's read it.
What is a superhero.
And then one two three in the line I'll go back into my temp directory and cat hawk and it is added
here as well.
So what is telling us that you could modify the source file you can modify the contents of the store
source file it will modify the destination link.
Just perfect.
Now let's go to my home directory again and this time I will remove pulk art how file is gone.
He confirmed it.
It's not there now.
I will go back to temp directory and I'll do it myself again and you will see the files still exist.
The link still exists and when we do Hulk and it does still have all the content we put it in.
Well OK so what is it telling us.
It's telling us that in the hardlink man you remove the source of the file.
It does not remove the destination.
So that's the basic difference is I'll go ahead and just remove this whole file as well.
The whole the link as well.
So please do remember the difference between soft link and hard link.
Many times these questions will be asked during the interview if you are not going for the interview.
If you are just wanted to level up your career have fun.