Okay, let's check out some links.
To start with, I want to show you LS L in the root of the file system.
So LS L is showing the long listing and there we can see some symbolic links.
So bin is pointing to user bin and lib is pointing to user lib and sbin
is pointing to user sbin. Now, why is that now? A long time ago, the file
system hierarchy standard was dictating that files that are required for booting your system are in
bin, and administrator files that are required for booting your system properly are in sbin.
And then we had user bin and usersbin with us for binaries
and super user binaries to be available once your system was booted.
That made Sense in the 1990s, but later it did not make sense anymore.
So the FHS changed and they removed the requirement for the bin directory.
But you can't just remove a directory because many organizations are creating scripts and other components or applications that
refer to the location of the file in a hard way. So if you will be referring to BinPassWD,
for instance, your script would fail to. And that is easily fixed by creating a symbolic link, which means
that bin is pointing to user bin and the result is that they show the same content.
Then, about a hard link, let me work out an example where you can see hard links.
I'm creating a directory and let's create a directory course one and let's create
a directory course two and then I'm going to create a configuration file.
Now a script.
Let's use a simple editor, nano. I'll talk about editors later. So for
now I want to keep it simple and let's call it Setup sh.
And in that script I'm going to use Echo hello world.
Of course this is oversimplified, but you don't need to make it more complex to make a point.
Let's say that for course one we need the Setup sh. We also need it for course two.
Now what is the problem? Well, I can of
course copy Setup sh into the Course 2 directory,
but if then my script has changed Echo hello
world, as well as oceans, whatever.
So now my script has changed and then the
problem is that we have two independent scripts.
If I would use LS set and make that a
long listing so that we can see the properties.
You can see that the Course 1 setup sh is bigger than the Course 2 setup sh.
Now, can you imagine that you have several directories that all need the same script,
and once you update the script, you want to update all of them. That's where
a hard link comes in handy. So I'm removing Course 2 setup sh, and I'm
going to link LN for link Course 1 setup sh to Course 2 setup sh.
So now that I've created my links, let me do an LS IL on start setup.
And what do we see? We see the hard link.
Now, how do we see a hard link? Well, that's why I included the I. I is for the inode number.
This is the inode number. Every file has a unique inode,
and this unique inode contains a complete administration of the fal.
And you can see the inode numbers are the same, the size of the FAL
is the same, and all the other properties of the file are the same.
So if I change, no matter which one, like course two setup sh
and I'm adding endmoon and I'm saving my file. Yes, and I'm using
my LS il, what do we see? I changed the one in course
two, and the one in course one has also changed.
So hard links are really pointers to the same inode. And the nice benefit of using these
hard links is that you can change whichever one and that will change all of them.
In a heart link, there is no relation anymore between the original and
the linked val that's different. For symbolic links, let's get into the Course1
directory and let me use ln s to create a symbolic link.
And I want setup sh to link to
install sh again ls il on star.
And there we can see that install sh is clearly appointed to setup sh.
It also has a different inode number, as you can see right here.
But what would happen if I remove setup sh?
Well, then LS IL on install sh is is marking
by color coding that something is going not well.
And that is because the link has become invalid, as we call it.
So I can look cat oninstall sh and there we can see
no search file or directory. That's because the link has become invalid.
But hey, can we easily fix this?
There we have the current setup, and yeah, we should be able to
fix that by just creating the hard link again. So ln for course
two setup sh and we link it to course one setup sh.
And now I'm using my tree command again, and there we can see
that everything is back to the original situation. So it's all fixed now.