WEBVTT

00:01.170 --> 00:02.490
Linking files.

00:02.520 --> 00:09.300
Linking files is a great option in the Linux file system if you need to maintain two or more copies

00:09.300 --> 00:14.820
of the same file on the system instead of having a separate physical copies, you can use one physical

00:14.820 --> 00:18.600
copy and multiple virtual copies called links.

00:18.630 --> 00:19.740
Actually, yeah.

00:19.770 --> 00:21.060
Links here like this.

00:21.150 --> 00:28.350
Let me actually open our ergonomics grommet and write it right down here.

00:28.800 --> 00:29.610
Yeah.

00:29.610 --> 00:30.570
Here.

00:30.600 --> 00:31.680
Links.

00:34.060 --> 00:34.270
Of.

00:40.100 --> 00:48.760
So a link is a placeholder in a directory that points to real location of a file.

00:48.770 --> 00:51.880
So there is a two type of links here.

00:51.890 --> 00:54.710
So let's actually make it circle.

00:54.710 --> 00:59.810
And the first type is a symbolic link.

01:03.190 --> 01:03.590
Here.

01:03.640 --> 01:04.840
Symbolic.

01:08.810 --> 01:12.110
And the second type is hard link.

01:17.060 --> 01:24.350
So a symbolic link is a symbol of a physical file that points to another file somewhere in the virtual

01:24.350 --> 01:25.430
directory structure.

01:25.430 --> 01:31.910
So that's to symbolically link together files, do not share the same contents.

01:31.910 --> 01:36.920
So to create a symbolic link to a file, the original file must pre-exist.

01:36.920 --> 01:43.070
So you can you can then use the ln command with the s option to create a symbolic link here.

01:43.070 --> 01:48.470
So here, for example, let's write our file.

01:50.060 --> 01:53.330
And here open our file manager open folder.

01:53.840 --> 01:57.500
And for example, let's create a test file.

01:57.510 --> 01:58.820
Write something in it.

02:00.440 --> 02:01.010
Here.

02:04.030 --> 02:04.780
And.

02:05.550 --> 02:12.300
So we have some 531 31 bytes in it that we will write it here.

02:12.300 --> 02:16.440
So we will do LSL here, test file.

02:16.440 --> 02:22.500
And here, as you can see here, we have bytes and the test file here.

02:22.500 --> 02:25.800
And as you can see, we have seen our permissions here.

02:25.800 --> 02:33.240
So in order to do that, we will use ln s and for example, we will do it the test file.

02:33.240 --> 02:40.980
Firstly, we will pass our file, real file, and then we will sl here test file or you can.

02:40.980 --> 02:41.190
Yeah.

02:41.190 --> 02:42.780
You can also use it like that.

02:42.780 --> 02:43.290
Yeah.

02:43.410 --> 02:47.760
They don't have to share the same name or same name structure.

02:47.880 --> 02:56.880
So in this example here let's actually ls l and here in this example, notice that the name of the symbolic

02:56.880 --> 03:00.240
link is L data file.

03:00.510 --> 03:12.220
Test file is a listed second in the l n comma and as you can see here, so the the symbol here actually

03:12.220 --> 03:14.710
let me and as you can see, this is the symbol here.

03:14.710 --> 03:22.900
This this symbol here displayed after the symbolic link files, long listing shows that it is symbolically

03:22.930 --> 03:30.580
linked, symbolically linked to the file test file, as you can see here.

03:31.150 --> 03:37.660
So also, I want to note that that symbolic link file size versus the data file size.

03:37.660 --> 03:50.440
So the symbolic link is L file size here is only nine bytes where our data file has let me yeah, 531

03:50.440 --> 03:51.520
bytes in it.

03:51.700 --> 04:01.240
So this is because the as our s l test file is only pointing to our test file.

04:01.240 --> 04:03.640
So it actually doesn't contain any contents in it.

04:04.580 --> 04:14.030
So they do not share contents and are they are physically two separate files in our directory file system.

04:14.030 --> 04:21.770
But this only this file is only purpose to show that where our test file is.

04:23.050 --> 04:29.290
So another way to tell these linked files are separate physical files, but by viewing their inode number

04:29.290 --> 04:35.950
so the inode number of a file directory is a unique identification number that the kernel assigns to

04:35.950 --> 04:37.660
each object in the file system.

04:37.660 --> 04:45.820
So to view a file or directory is inode number, you can simply use the e parameter here.

04:46.030 --> 04:50.560
Actually it's clear and you can simply use E parameter right here.

04:50.560 --> 04:55.030
And then after that we will pass our test file, test file.

04:55.300 --> 05:03.760
And as you can see, this is our inode number for our test file and that's actually in here.

05:03.760 --> 05:06.340
And the oops, not like this.

05:08.540 --> 05:11.360
Let's clear this file.

05:11.360 --> 05:12.080
And then.

05:16.490 --> 05:17.510
We will do.

05:18.230 --> 05:19.040
Not like this.

05:19.040 --> 05:19.450
Yeah.

05:19.880 --> 05:20.330
Test file.

05:20.330 --> 05:21.860
We're going to write it right here.

05:22.190 --> 05:24.500
So test file.

05:24.500 --> 05:29.510
And here we will do SL test.

05:31.040 --> 05:31.730
File.

05:32.980 --> 05:37.870
And as you can see here, they are two different inode numbers.

05:37.990 --> 05:43.660
So remember that inode numbers are only assigned once in every file here.

05:43.660 --> 05:50.890
So there cannot be two inode files for now, but you will learn about inode numbers in next lectures.

05:51.830 --> 05:52.550
So.

05:54.700 --> 05:58.330
Another way to tell here that we can also.

05:58.960 --> 06:05.260
Yeah, this example showed us that the file inode number, our data file inode number is nine.

06:05.950 --> 06:10.300
Our data file inode number is 3932329.

06:10.660 --> 06:18.550
While our test file is 3932659.

06:18.760 --> 06:19.870
As you can see here.

06:19.870 --> 06:24.010
So a hard link creates a separate virtual file.

06:24.010 --> 06:26.020
So actually they are the different files.

06:26.020 --> 06:26.340
Right?

06:26.350 --> 06:27.030
We got it.

06:27.040 --> 06:27.640
Yeah, they are.

06:27.640 --> 06:29.590
The different files, the whole different files.

06:29.590 --> 06:35.140
But the hard link creates a separate virtual file that contains information about the original file

06:35.140 --> 06:37.060
and where to locate it.

06:37.060 --> 06:39.370
However, they are physically the same file.

06:39.370 --> 06:46.180
So when you reference the hard link file, it is just as if you are referencing the original file.

06:46.980 --> 06:53.460
So to create a hard link again, the original file must pre-exist.

06:53.460 --> 06:55.530
In this case, our original file is my test file.

06:55.890 --> 07:00.330
Except that this time there is a no parameter is needed on the command.

07:00.330 --> 07:06.540
In order to do that we're going to create LN So actually we learned about the symbolic line here.

07:06.540 --> 07:07.650
So we learned about symbolic.

07:07.650 --> 07:10.590
Now we're going to learn about the hard link lines.

07:10.590 --> 07:15.570
So now we're going to write ln my test file.

07:15.570 --> 07:19.110
My test file, and after that we're going to use the hard link.

07:19.110 --> 07:24.540
So in this case, as l that we mentioned, that ls l is a symbolic.

07:24.540 --> 07:29.730
And in this case let's actually write hard link to notify us that this is the hard link file or another

07:29.730 --> 07:35.940
users that notify us that this is a hard link file and not symbolic file symbolic link.

07:36.090 --> 07:39.300
So in this case let's actually

07:41.550 --> 07:43.530
test file.

07:45.120 --> 07:47.940
And here we created our hardlink file.

07:48.030 --> 07:48.870
Clear.

07:48.900 --> 07:52.920
LZ le LZ, L Yeah.

07:54.080 --> 07:54.770
Here.

07:56.090 --> 07:57.330
And let's find where.

07:57.380 --> 07:57.770
Yeah.

07:57.800 --> 08:01.120
As you can see here, this is test file Hardlink file.

08:01.130 --> 08:04.430
So in this example, actually, we need also.

08:05.690 --> 08:06.010
Great.

08:06.020 --> 08:08.450
Let's actually create the.

08:10.090 --> 08:10.510
First.

08:10.520 --> 08:14.440
Let's Yeah, let's actually and I will explain all of this here.

08:14.700 --> 08:15.490
Lee here.

08:15.490 --> 08:23.140
And we will make it what was actually what was our hardlink file here in this case is our test file

08:23.140 --> 08:26.920
and LSL here code.

08:27.860 --> 08:29.380
Caught ops?

08:29.420 --> 08:30.750
No, not caught here.

08:30.770 --> 08:31.430
Test File.

08:31.940 --> 08:33.050
Test file.

08:33.290 --> 08:35.880
And here, as you can see, zero bytes.

08:35.900 --> 08:38.630
And now let's actually use our.

08:40.050 --> 08:42.720
Our my test file.

08:44.170 --> 08:44.710
Yeah.

08:45.730 --> 08:47.100
Oh, actually I forgot about.

08:47.140 --> 08:48.340
We are working with.

08:48.370 --> 08:50.460
Yeah, it has to be test file.

08:50.470 --> 08:50.760
Yeah.

08:50.770 --> 08:51.580
Test file.

08:55.870 --> 08:56.050
In.

08:56.050 --> 08:59.260
Previously, we we actually created a wrong file name.

08:59.610 --> 09:03.670
We need to create a test file here so we will delete it.

09:03.670 --> 09:07.120
And as you can see, I'm going to show how it will hardlink files look like.

09:07.120 --> 09:14.140
And as you can see, WSL has a thick like this in the graphical interface but has doesn't have any things.

09:14.140 --> 09:18.360
And here, as you can see here, it's empty because we created from the empty file.

09:18.370 --> 09:20.500
Actually, my test file is empty as you can see here.

09:20.500 --> 09:23.230
So let's also delete this.

09:25.160 --> 09:25.600
Here.

09:25.670 --> 09:26.420
Yeah.

09:27.470 --> 09:31.140
Now we're going to use the test file, which is we've written some contents in it.

09:32.190 --> 09:39.420
Here and now we're going to use the LZ l e here.

09:41.610 --> 09:42.010
Oh, no.

09:42.030 --> 09:46.350
Firstly, we're going to create the ln or my test file.

09:46.380 --> 09:47.490
Or test file.

09:47.520 --> 09:48.840
Test file.

09:48.840 --> 09:51.060
And after that, my.

09:51.060 --> 09:52.230
Or test file.

09:52.320 --> 09:52.560
Right.

09:52.560 --> 09:53.520
Just the test file.

09:53.550 --> 09:58.140
File Create a hard link because the test file hard link is actually test file.

09:58.350 --> 09:59.760
My text file here.

09:59.760 --> 10:01.590
My test file.

10:01.590 --> 10:03.360
And we created our hard link.

10:03.360 --> 10:07.050
And now we're going to also show our hard link file here.

10:07.050 --> 10:10.230
So la la here.

10:10.230 --> 10:11.550
So in this case, we're going to.

10:13.270 --> 10:14.890
Use that test.

10:15.430 --> 10:16.840
Test file.

10:18.550 --> 10:19.030
File.

10:19.030 --> 10:21.550
And here, as you can see, we got another example.

10:21.550 --> 10:29.890
So in this example, we use the LSL command to show both the inode numbers and the long listing numbers

10:29.890 --> 10:31.000
for the code files.

10:31.000 --> 10:39.160
Actually, let's also show I want to show you how our inode number looks of our hardlink file, in this

10:39.160 --> 10:42.160
case, my test file.

10:42.160 --> 10:47.040
And here, as you can see here, these are inode numbers are the same.

10:47.050 --> 10:47.860
So.

10:49.640 --> 10:54.290
At these port files which are hard linked together, share the same inode number.

10:54.320 --> 10:56.750
This is because they are physically the same file.

10:57.110 --> 11:03.280
And as you can see, these all of them are the same size.

11:03.290 --> 11:05.270
This is because they are physically same file.

11:05.420 --> 11:06.560
And the.

11:07.790 --> 11:09.620
Here we have two links.

11:09.620 --> 11:16.610
In addition, their file size is exactly the same as well, so be careful when copying the linked files

11:16.610 --> 11:19.130
if you are using the CP command.

11:19.370 --> 11:20.500
Actually let's take it.

11:20.510 --> 11:20.810
Yeah.

11:20.810 --> 11:27.310
If you use the CP command to copy a file that's linked to another source file, all you are doing is

11:27.350 --> 11:31.420
making another copy of the source file so this can quickly get confusing.

11:31.430 --> 11:37.520
Instead of copying the link file, you can create another linked to the original file and you can have

11:37.520 --> 11:39.890
many links to the same file with no problems.

11:39.890 --> 11:47.090
However, you also don't want to create a soft links to the other to the other soft linked files.

11:47.090 --> 11:54.950
So this creates a chain of links that can be confusing and easily broken, causing all sorts of problems.

11:54.950 --> 11:58.640
So you may find symbolic and hard link difficult concepts.

11:58.640 --> 12:04.220
Fortunately, renaming files in the next lecture you is a great deal easier to understand that.

12:04.220 --> 12:06.140
So I'm waiting you in next lecture.
