1 00:00:01,170 --> 00:00:02,490 Linking files. 2 00:00:02,520 --> 00:00:09,300 Linking files is a great option in the Linux file system if you need to maintain two or more copies 3 00:00:09,300 --> 00:00:14,820 of the same file on the system instead of having a separate physical copies, you can use one physical 4 00:00:14,820 --> 00:00:18,600 copy and multiple virtual copies called links. 5 00:00:18,630 --> 00:00:19,740 Actually, yeah. 6 00:00:19,770 --> 00:00:21,060 Links here like this. 7 00:00:21,150 --> 00:00:28,350 Let me actually open our ergonomics grommet and write it right down here. 8 00:00:28,800 --> 00:00:29,610 Yeah. 9 00:00:29,610 --> 00:00:30,570 Here. 10 00:00:30,600 --> 00:00:31,680 Links. 11 00:00:34,060 --> 00:00:34,270 Of. 12 00:00:40,100 --> 00:00:48,760 So a link is a placeholder in a directory that points to real location of a file. 13 00:00:48,770 --> 00:00:51,880 So there is a two type of links here. 14 00:00:51,890 --> 00:00:54,710 So let's actually make it circle. 15 00:00:54,710 --> 00:00:59,810 And the first type is a symbolic link. 16 00:01:03,190 --> 00:01:03,590 Here. 17 00:01:03,640 --> 00:01:04,840 Symbolic. 18 00:01:08,810 --> 00:01:12,110 And the second type is hard link. 19 00:01:17,060 --> 00:01:24,350 So a symbolic link is a symbol of a physical file that points to another file somewhere in the virtual 20 00:01:24,350 --> 00:01:25,430 directory structure. 21 00:01:25,430 --> 00:01:31,910 So that's to symbolically link together files, do not share the same contents. 22 00:01:31,910 --> 00:01:36,920 So to create a symbolic link to a file, the original file must pre-exist. 23 00:01:36,920 --> 00:01:43,070 So you can you can then use the ln command with the s option to create a symbolic link here. 24 00:01:43,070 --> 00:01:48,470 So here, for example, let's write our file. 25 00:01:50,060 --> 00:01:53,330 And here open our file manager open folder. 26 00:01:53,840 --> 00:01:57,500 And for example, let's create a test file. 27 00:01:57,510 --> 00:01:58,820 Write something in it. 28 00:02:00,440 --> 00:02:01,010 Here. 29 00:02:04,030 --> 00:02:04,780 And. 30 00:02:05,550 --> 00:02:12,300 So we have some 531 31 bytes in it that we will write it here. 31 00:02:12,300 --> 00:02:16,440 So we will do LSL here, test file. 32 00:02:16,440 --> 00:02:22,500 And here, as you can see here, we have bytes and the test file here. 33 00:02:22,500 --> 00:02:25,800 And as you can see, we have seen our permissions here. 34 00:02:25,800 --> 00:02:33,240 So in order to do that, we will use ln s and for example, we will do it the test file. 35 00:02:33,240 --> 00:02:40,980 Firstly, we will pass our file, real file, and then we will sl here test file or you can. 36 00:02:40,980 --> 00:02:41,190 Yeah. 37 00:02:41,190 --> 00:02:42,780 You can also use it like that. 38 00:02:42,780 --> 00:02:43,290 Yeah. 39 00:02:43,410 --> 00:02:47,760 They don't have to share the same name or same name structure. 40 00:02:47,880 --> 00: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 41 00:02:56,880 --> 00:03:00,240 link is L data file. 42 00:03:00,510 --> 00: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 43 00:03:12,220 --> 00:03:14,710 let me and as you can see, this is the symbol here. 44 00:03:14,710 --> 00:03:22,900 This this symbol here displayed after the symbolic link files, long listing shows that it is symbolically 45 00:03:22,930 --> 00:03:30,580 linked, symbolically linked to the file test file, as you can see here. 46 00:03:31,150 --> 00:03:37,660 So also, I want to note that that symbolic link file size versus the data file size. 47 00:03:37,660 --> 00: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 48 00:03:50,440 --> 00:03:51,520 bytes in it. 49 00:03:51,700 --> 00:04:01,240 So this is because the as our s l test file is only pointing to our test file. 50 00:04:01,240 --> 00:04:03,640 So it actually doesn't contain any contents in it. 51 00:04:04,580 --> 00:04:14,030 So they do not share contents and are they are physically two separate files in our directory file system. 52 00:04:14,030 --> 00:04:21,770 But this only this file is only purpose to show that where our test file is. 53 00:04:23,050 --> 00:04:29,290 So another way to tell these linked files are separate physical files, but by viewing their inode number 54 00:04:29,290 --> 00:04:35,950 so the inode number of a file directory is a unique identification number that the kernel assigns to 55 00:04:35,950 --> 00:04:37,660 each object in the file system. 56 00:04:37,660 --> 00:04:45,820 So to view a file or directory is inode number, you can simply use the e parameter here. 57 00:04:46,030 --> 00:04:50,560 Actually it's clear and you can simply use E parameter right here. 58 00:04:50,560 --> 00:04:55,030 And then after that we will pass our test file, test file. 59 00:04:55,300 --> 00:05:03,760 And as you can see, this is our inode number for our test file and that's actually in here. 60 00:05:03,760 --> 00:05:06,340 And the oops, not like this. 61 00:05:08,540 --> 00:05:11,360 Let's clear this file. 62 00:05:11,360 --> 00:05:12,080 And then. 63 00:05:16,490 --> 00:05:17,510 We will do. 64 00:05:18,230 --> 00:05:19,040 Not like this. 65 00:05:19,040 --> 00:05:19,450 Yeah. 66 00:05:19,880 --> 00:05:20,330 Test file. 67 00:05:20,330 --> 00:05:21,860 We're going to write it right here. 68 00:05:22,190 --> 00:05:24,500 So test file. 69 00:05:24,500 --> 00:05:29,510 And here we will do SL test. 70 00:05:31,040 --> 00:05:31,730 File. 71 00:05:32,980 --> 00:05:37,870 And as you can see here, they are two different inode numbers. 72 00:05:37,990 --> 00:05:43,660 So remember that inode numbers are only assigned once in every file here. 73 00:05:43,660 --> 00:05:50,890 So there cannot be two inode files for now, but you will learn about inode numbers in next lectures. 74 00:05:51,830 --> 00:05:52,550 So. 75 00:05:54,700 --> 00:05:58,330 Another way to tell here that we can also. 76 00:05:58,960 --> 00:06:05,260 Yeah, this example showed us that the file inode number, our data file inode number is nine. 77 00:06:05,950 --> 00:06:10,300 Our data file inode number is 3932329. 78 00:06:10,660 --> 00:06:18,550 While our test file is 3932659. 79 00:06:18,760 --> 00:06:19,870 As you can see here. 80 00:06:19,870 --> 00:06:24,010 So a hard link creates a separate virtual file. 81 00:06:24,010 --> 00:06:26,020 So actually they are the different files. 82 00:06:26,020 --> 00:06:26,340 Right? 83 00:06:26,350 --> 00:06:27,030 We got it. 84 00:06:27,040 --> 00:06:27,640 Yeah, they are. 85 00:06:27,640 --> 00:06:29,590 The different files, the whole different files. 86 00:06:29,590 --> 00:06:35,140 But the hard link creates a separate virtual file that contains information about the original file 87 00:06:35,140 --> 00:06:37,060 and where to locate it. 88 00:06:37,060 --> 00:06:39,370 However, they are physically the same file. 89 00:06:39,370 --> 00:06:46,180 So when you reference the hard link file, it is just as if you are referencing the original file. 90 00:06:46,980 --> 00:06:53,460 So to create a hard link again, the original file must pre-exist. 91 00:06:53,460 --> 00:06:55,530 In this case, our original file is my test file. 92 00:06:55,890 --> 00:07:00,330 Except that this time there is a no parameter is needed on the command. 93 00:07:00,330 --> 00:07:06,540 In order to do that we're going to create LN So actually we learned about the symbolic line here. 94 00:07:06,540 --> 00:07:07,650 So we learned about symbolic. 95 00:07:07,650 --> 00:07:10,590 Now we're going to learn about the hard link lines. 96 00:07:10,590 --> 00:07:15,570 So now we're going to write ln my test file. 97 00:07:15,570 --> 00:07:19,110 My test file, and after that we're going to use the hard link. 98 00:07:19,110 --> 00:07:24,540 So in this case, as l that we mentioned, that ls l is a symbolic. 99 00:07:24,540 --> 00: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 100 00:07:29,730 --> 00:07:35,940 users that notify us that this is a hard link file and not symbolic file symbolic link. 101 00:07:36,090 --> 00:07:39,300 So in this case let's actually 102 00:07:41,550 --> 00:07:43,530 test file. 103 00:07:45,120 --> 00:07:47,940 And here we created our hardlink file. 104 00:07:48,030 --> 00:07:48,870 Clear. 105 00:07:48,900 --> 00:07:52,920 LZ le LZ, L Yeah. 106 00:07:54,080 --> 00:07:54,770 Here. 107 00:07:56,090 --> 00:07:57,330 And let's find where. 108 00:07:57,380 --> 00:07:57,770 Yeah. 109 00:07:57,800 --> 00:08:01,120 As you can see here, this is test file Hardlink file. 110 00:08:01,130 --> 00:08:04,430 So in this example, actually, we need also. 111 00:08:05,690 --> 00:08:06,010 Great. 112 00:08:06,020 --> 00:08:08,450 Let's actually create the. 113 00:08:10,090 --> 00:08:10,510 First. 114 00:08:10,520 --> 00:08:14,440 Let's Yeah, let's actually and I will explain all of this here. 115 00:08:14,700 --> 00:08:15,490 Lee here. 116 00:08:15,490 --> 00:08:23,140 And we will make it what was actually what was our hardlink file here in this case is our test file 117 00:08:23,140 --> 00:08:26,920 and LSL here code. 118 00:08:27,860 --> 00:08:29,380 Caught ops? 119 00:08:29,420 --> 00:08:30,750 No, not caught here. 120 00:08:30,770 --> 00:08:31,430 Test File. 121 00:08:31,940 --> 00:08:33,050 Test file. 122 00:08:33,290 --> 00:08:35,880 And here, as you can see, zero bytes. 123 00:08:35,900 --> 00:08:38,630 And now let's actually use our. 124 00:08:40,050 --> 00:08:42,720 Our my test file. 125 00:08:44,170 --> 00:08:44,710 Yeah. 126 00:08:45,730 --> 00:08:47,100 Oh, actually I forgot about. 127 00:08:47,140 --> 00:08:48,340 We are working with. 128 00:08:48,370 --> 00:08:50,460 Yeah, it has to be test file. 129 00:08:50,470 --> 00:08:50,760 Yeah. 130 00:08:50,770 --> 00:08:51,580 Test file. 131 00:08:55,870 --> 00:08:56,050 In. 132 00:08:56,050 --> 00:08:59,260 Previously, we we actually created a wrong file name. 133 00:08:59,610 --> 00:09:03,670 We need to create a test file here so we will delete it. 134 00:09:03,670 --> 00:09:07,120 And as you can see, I'm going to show how it will hardlink files look like. 135 00:09:07,120 --> 00: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. 136 00:09:14,140 --> 00:09:18,360 And here, as you can see here, it's empty because we created from the empty file. 137 00:09:18,370 --> 00:09:20,500 Actually, my test file is empty as you can see here. 138 00:09:20,500 --> 00:09:23,230 So let's also delete this. 139 00:09:25,160 --> 00:09:25,600 Here. 140 00:09:25,670 --> 00:09:26,420 Yeah. 141 00:09:27,470 --> 00:09:31,140 Now we're going to use the test file, which is we've written some contents in it. 142 00:09:32,190 --> 00:09:39,420 Here and now we're going to use the LZ l e here. 143 00:09:41,610 --> 00:09:42,010 Oh, no. 144 00:09:42,030 --> 00:09:46,350 Firstly, we're going to create the ln or my test file. 145 00:09:46,380 --> 00:09:47,490 Or test file. 146 00:09:47,520 --> 00:09:48,840 Test file. 147 00:09:48,840 --> 00:09:51,060 And after that, my. 148 00:09:51,060 --> 00:09:52,230 Or test file. 149 00:09:52,320 --> 00:09:52,560 Right. 150 00:09:52,560 --> 00:09:53,520 Just the test file. 151 00:09:53,550 --> 00:09:58,140 File Create a hard link because the test file hard link is actually test file. 152 00:09:58,350 --> 00:09:59,760 My text file here. 153 00:09:59,760 --> 00:10:01,590 My test file. 154 00:10:01,590 --> 00:10:03,360 And we created our hard link. 155 00:10:03,360 --> 00:10:07,050 And now we're going to also show our hard link file here. 156 00:10:07,050 --> 00:10:10,230 So la la here. 157 00:10:10,230 --> 00:10:11,550 So in this case, we're going to. 158 00:10:13,270 --> 00:10:14,890 Use that test. 159 00:10:15,430 --> 00:10:16,840 Test file. 160 00:10:18,550 --> 00:10:19,030 File. 161 00:10:19,030 --> 00:10:21,550 And here, as you can see, we got another example. 162 00:10:21,550 --> 00:10:29,890 So in this example, we use the LSL command to show both the inode numbers and the long listing numbers 163 00:10:29,890 --> 00:10:31,000 for the code files. 164 00:10:31,000 --> 00:10:39,160 Actually, let's also show I want to show you how our inode number looks of our hardlink file, in this 165 00:10:39,160 --> 00:10:42,160 case, my test file. 166 00:10:42,160 --> 00:10:47,040 And here, as you can see here, these are inode numbers are the same. 167 00:10:47,050 --> 00:10:47,860 So. 168 00:10:49,640 --> 00:10:54,290 At these port files which are hard linked together, share the same inode number. 169 00:10:54,320 --> 00:10:56,750 This is because they are physically the same file. 170 00:10:57,110 --> 00:11:03,280 And as you can see, these all of them are the same size. 171 00:11:03,290 --> 00:11:05,270 This is because they are physically same file. 172 00:11:05,420 --> 00:11:06,560 And the. 173 00:11:07,790 --> 00:11:09,620 Here we have two links. 174 00:11:09,620 --> 00:11:16,610 In addition, their file size is exactly the same as well, so be careful when copying the linked files 175 00:11:16,610 --> 00:11:19,130 if you are using the CP command. 176 00:11:19,370 --> 00:11:20,500 Actually let's take it. 177 00:11:20,510 --> 00:11:20,810 Yeah. 178 00:11:20,810 --> 00: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 179 00:11:27,350 --> 00:11:31,420 making another copy of the source file so this can quickly get confusing. 180 00:11:31,430 --> 00:11:37,520 Instead of copying the link file, you can create another linked to the original file and you can have 181 00:11:37,520 --> 00:11:39,890 many links to the same file with no problems. 182 00:11:39,890 --> 00:11:47,090 However, you also don't want to create a soft links to the other to the other soft linked files. 183 00:11:47,090 --> 00:11:54,950 So this creates a chain of links that can be confusing and easily broken, causing all sorts of problems. 184 00:11:54,950 --> 00:11:58,640 So you may find symbolic and hard link difficult concepts. 185 00:11:58,640 --> 00:12:04,220 Fortunately, renaming files in the next lecture you is a great deal easier to understand that. 186 00:12:04,220 --> 00:12:06,140 So I'm waiting you in next lecture.