Linking files.
Linking files is a great option in the Linux file system if you need to maintain two or more copies
of the same file on the system instead of having a separate physical copies, you can use one physical
copy and multiple virtual copies called links.
Actually, yeah.
Links here like this.
Let me actually open our ergonomics grommet and write it right down here.
Yeah.
Here.
Links.
Of.
So a link is a placeholder in a directory that points to real location of a file.
So there is a two type of links here.
So let's actually make it circle.
And the first type is a symbolic link.
Here.
Symbolic.
And the second type is hard link.
So a symbolic link is a symbol of a physical file that points to another file somewhere in the virtual
directory structure.
So that's to symbolically link together files, do not share the same contents.
So to create a symbolic link to a file, the original file must pre-exist.
So you can you can then use the ln command with the s option to create a symbolic link here.
So here, for example, let's write our file.
And here open our file manager open folder.
And for example, let's create a test file.
Write something in it.
Here.
And.
So we have some 531 31 bytes in it that we will write it here.
So we will do LSL here, test file.
And here, as you can see here, we have bytes and the test file here.
And as you can see, we have seen our permissions here.
So in order to do that, we will use ln s and for example, we will do it the test file.
Firstly, we will pass our file, real file, and then we will sl here test file or you can.
Yeah.
You can also use it like that.
Yeah.
They don't have to share the same name or same name structure.
So in this example here let's actually ls l and here in this example, notice that the name of the symbolic
link is L data file.
Test file is a listed second in the l n comma and as you can see here, so the the symbol here actually
let me and as you can see, this is the symbol here.
This this symbol here displayed after the symbolic link files, long listing shows that it is symbolically
linked, symbolically linked to the file test file, as you can see here.
So also, I want to note that that symbolic link file size versus the data file size.
So the symbolic link is L file size here is only nine bytes where our data file has let me yeah, 531
bytes in it.
So this is because the as our s l test file is only pointing to our test file.
So it actually doesn't contain any contents in it.
So they do not share contents and are they are physically two separate files in our directory file system.
But this only this file is only purpose to show that where our test file is.
So another way to tell these linked files are separate physical files, but by viewing their inode number
so the inode number of a file directory is a unique identification number that the kernel assigns to
each object in the file system.
So to view a file or directory is inode number, you can simply use the e parameter here.
Actually it's clear and you can simply use E parameter right here.
And then after that we will pass our test file, test file.
And as you can see, this is our inode number for our test file and that's actually in here.
And the oops, not like this.
Let's clear this file.
And then.
We will do.
Not like this.
Yeah.
Test file.
We're going to write it right here.
So test file.
And here we will do SL test.
File.
And as you can see here, they are two different inode numbers.
So remember that inode numbers are only assigned once in every file here.
So there cannot be two inode files for now, but you will learn about inode numbers in next lectures.
So.
Another way to tell here that we can also.
Yeah, this example showed us that the file inode number, our data file inode number is nine.
Our data file inode number is 3932329.
While our test file is 3932659.
As you can see here.
So a hard link creates a separate virtual file.
So actually they are the different files.
Right?
We got it.
Yeah, they are.
The different files, the whole different files.
But the hard link creates a separate virtual file that contains information about the original file
and where to locate it.
However, they are physically the same file.
So when you reference the hard link file, it is just as if you are referencing the original file.
So to create a hard link again, the original file must pre-exist.
In this case, our original file is my test file.
Except that this time there is a no parameter is needed on the command.
In order to do that we're going to create LN So actually we learned about the symbolic line here.
So we learned about symbolic.
Now we're going to learn about the hard link lines.
So now we're going to write ln my test file.
My test file, and after that we're going to use the hard link.
So in this case, as l that we mentioned, that ls l is a symbolic.
And in this case let's actually write hard link to notify us that this is the hard link file or another
users that notify us that this is a hard link file and not symbolic file symbolic link.
So in this case let's actually
test file.
And here we created our hardlink file.
Clear.
LZ le LZ, L Yeah.
Here.
And let's find where.
Yeah.
As you can see here, this is test file Hardlink file.
So in this example, actually, we need also.
Great.
Let's actually create the.
First.
Let's Yeah, let's actually and I will explain all of this here.
Lee here.
And we will make it what was actually what was our hardlink file here in this case is our test file
and LSL here code.
Caught ops?
No, not caught here.
Test File.
Test file.
And here, as you can see, zero bytes.
And now let's actually use our.
Our my test file.
Yeah.
Oh, actually I forgot about.
We are working with.
Yeah, it has to be test file.
Yeah.
Test file.
In.
Previously, we we actually created a wrong file name.
We need to create a test file here so we will delete it.
And as you can see, I'm going to show how it will hardlink files look like.
And as you can see, WSL has a thick like this in the graphical interface but has doesn't have any things.
And here, as you can see here, it's empty because we created from the empty file.
Actually, my test file is empty as you can see here.
So let's also delete this.
Here.
Yeah.
Now we're going to use the test file, which is we've written some contents in it.
Here and now we're going to use the LZ l e here.
Oh, no.
Firstly, we're going to create the ln or my test file.
Or test file.
Test file.
And after that, my.
Or test file.
Right.
Just the test file.
File Create a hard link because the test file hard link is actually test file.
My text file here.
My test file.
And we created our hard link.
And now we're going to also show our hard link file here.
So la la here.
So in this case, we're going to.
Use that test.
Test file.
File.
And here, as you can see, we got another example.
So in this example, we use the LSL command to show both the inode numbers and the long listing numbers
for the code files.
Actually, let's also show I want to show you how our inode number looks of our hardlink file, in this
case, my test file.
And here, as you can see here, these are inode numbers are the same.
So.
At these port files which are hard linked together, share the same inode number.
This is because they are physically the same file.
And as you can see, these all of them are the same size.
This is because they are physically same file.
And the.
Here we have two links.
In addition, their file size is exactly the same as well, so be careful when copying the linked files
if you are using the CP command.
Actually let's take it.
Yeah.
If you use the CP command to copy a file that's linked to another source file, all you are doing is
making another copy of the source file so this can quickly get confusing.
Instead of copying the link file, you can create another linked to the original file and you can have
many links to the same file with no problems.
However, you also don't want to create a soft links to the other to the other soft linked files.
So this creates a chain of links that can be confusing and easily broken, causing all sorts of problems.
So you may find symbolic and hard link difficult concepts.
Fortunately, renaming files in the next lecture you is a great deal easier to understand that.
So I'm waiting you in next lecture.