Soft links and hard links.
This is one of the important topics in Linux before I tell you anything about what a soft link and hard
link is.
I have to tell you, I knowed what I note as I note as basically a pointer or a number of a file on
a hard disk.
So if I create a file called let's say, Hulk, that file name is elk.
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 you 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.A., and every time we try to retrieve that file or read the file, it goes
and retrieve that number.
So now now you know that 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 if I remove the source file, it will remove the destination link where as hard link is, when deleting
or renaming the source file, the hard link will not change.
It will remain the same as if you have copied it.
To create a hard link command, you will run L 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 AI node, whereas my hard link is connecting straight to the
AI node.
So if the middle part, which is my file, that tax goes away, my soft link goes away.
However, in my hard link file, if middle file my file tax goes away, it doesn't matter.
They'll file stays.
Let us get that log in to our machine, a Linux machine, and I will explain you much better how this
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 and your Windows environment, you have a file located somewhere
in Windows System32, blah blah, blah blah.
Of course, you have to go to that file all the time by navigating through that file system.
Click Click, Click.
Click, Click.
Click, Click Click.
Hmm.
So much work, man.
So what do we do?
We create a shortcut to our desktop.
All you have to do is double click on bombing runs.
Just like that, we have Linux soft and heart link.
So without further ado, I'm going to log in to my machine and I'll explain you, and this is our machine
is going to drag it a little more to the left.
Just wanted to confirm again it.
I am logged in as myself.
This is my name.
This is my home directory.
Perfect.
I want to create a file called Hulk.
Everybody knows Hulk.
Great fun character.
Big giant character.
I like it 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 am in temp.
Not in my home directory.
And I want to create Link soft link to Hulk and Hulk file location his home.
I have sole and the name of the file is Hulk.
Boom.
It created the file link.
How do we verify your friendly command?
That's minus L tr.
And if you see right at the bottom, it is telling you it has created a link and Linux operating system.
Since we are running Linux with the Goias changes, some of the color, it changes it to blue.
So right here, the first bit it's telling you it is L what is L four l is for link.
What is D for?
D is for directory.
Yes, very good.
And what is a file that does not have anything, of course, is 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 p wd to just confirm I am in my home.
Correct?
Yes, I am, and I will type something in my file called Hulk, so I'll do echo and do.
Hulk is a super hero, OK, and I'll put that to Hulk file and 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 yes, and I'm going to cat the Hulk.
And you see, it has the same content that I just typed in.
So it's just a shortcut, just a link.
Now we'll come back to my home directory and I will run LS minus L.
I.
What is I?
I stands for I notice if I wanted to find out the I know off this file, I would run I.
So yeah, it's there.
But since I didn't type L s minus L TR, it went into middle type.
I lost my l tr and then I.
So this way we'll be at the bottom.
So if you see that I node number right here is the number that is associated with my file.
Hook Yeah.
Again, I note is the number that is remembered by your operating system and it is on your desk.
It doesn't remember Hulk.
When I go to a temp and do LS, myself TR and right here, if I do, it's minus l tr i 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 L s minus L tr i and I'm going into home.
I have so.
Look, it has a different I.A., so this one is remembered as a different file is remembering at its
length, it does not know that it is actually a file.
It just knows it 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.
But if I just type, Hulk will just give me Hulk name.
So Hulk is there, but it's no longer blue or it's look crooked.
Y looks crooked because the file is gone.
If I do cat right now and do Hulk, 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 it's better.
Then I'll just remove the link as well and just verify it.
It's gone.
If I just want to do it as myself, TR just do Hulk.
Yeah, see no file.
So that's how the soft link works.
Now I will explain you how the hard link works.
Let's go and create our file again.
We'll call it Hulk Hogan and I will put something inside the file.
Echo Hulk is a super hero.
OK, I'll put that in Hulk hardware verified.
We'll just look at the file.
And yes, Hulk is a superhero.
The continent's there.
Now I will go into temp directory and I want to link to this file creating hard link.
You see, I'm not going with minus s option s stands for soft link, so I'll do link home.
I have saw Hulk.
Link created How do we verified?
You just run Alice minus l tr and you will see at the bottom, it's telling me.
That the link is created now, the difference between this link, hard link and the soft link is that
there is no pointing to other file.
That is the difference of Heart Link Assault Link.
Now if you are read, if I read the content of this file, it says Hulk is a superhero of the same content.
Everything is same.
Now let me go back to my home directory.
I'm in the home directory.
Let's check that Hulk file and I will write down something else in it now.
Echo.
One, two, three and then two hook.
Let's read it.
Hulk is a superhero and then one two three in the line, I'll go back into my temp directory and cat
Hulk, and it is added here as well.
So what is telling us that you can modify the source file?
You can modify the contents of the source file.
It will modify the destination link, which is perfect.
Now let's go to my home directory again, and this time I will remove Hulk.
All right, Hulk file is gone.
He confirmed it.
It's not there now.
I will go back to Temp Directory and I will do LS minus l tr again and you will see the file still exist.
The link still exist.
And when we do Hulk and it does still have all the contents of you put it in.
Well, OK, so what is it telling us?
It's telling us that in the hard link, when 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 Hulk file as well, the Hulk link
as well.
So please do remember the difference between soft link and heart link.
Have fun.