1 00:00:00,810 --> 00:00:03,900 Instructor: Okay, so we know how to find our way 2 00:00:03,900 --> 00:00:06,810 to the desired directory in terminal, 3 00:00:06,810 --> 00:00:09,510 but what if we need to create a file 4 00:00:09,510 --> 00:00:12,630 or a sub folder in another directory? 5 00:00:12,630 --> 00:00:14,370 How can we do that? 6 00:00:14,370 --> 00:00:17,070 Well first let's open up our terminal. 7 00:00:17,070 --> 00:00:20,700 And by the way, another way that you can open terminal 8 00:00:20,700 --> 00:00:24,870 instead of right clicking and going open terminal here, 9 00:00:24,870 --> 00:00:27,930 is going up here to this icon which says, 10 00:00:27,930 --> 00:00:31,263 terminal emulator and clicking on it. 11 00:00:32,369 --> 00:00:36,060 By default, this will be inside of your home directory, 12 00:00:36,060 --> 00:00:38,310 which we know to be this sign. 13 00:00:38,310 --> 00:00:40,590 And if we type the PWD command, 14 00:00:40,590 --> 00:00:44,490 we get slash home slash Mr. Hacker directory. 15 00:00:44,490 --> 00:00:46,140 We know that our desktop directory 16 00:00:46,140 --> 00:00:49,440 is also inside of this directory, so let's go there. 17 00:00:49,440 --> 00:00:52,170 CD desktop, press enter, 18 00:00:52,170 --> 00:00:54,483 and now we are in the desktop directory. 19 00:00:55,380 --> 00:00:57,450 Let's get back to the files. 20 00:00:57,450 --> 00:00:59,580 To create a simple empty file, 21 00:00:59,580 --> 00:01:03,060 we can use a command called touch. 22 00:01:03,060 --> 00:01:06,510 If I simply just type touch file 23 00:01:06,510 --> 00:01:10,740 and let's call it file one, press enter. 24 00:01:10,740 --> 00:01:13,230 This will create the file named file one 25 00:01:13,230 --> 00:01:16,173 and it'll have no contents inside of it. 26 00:01:17,190 --> 00:01:19,950 We can also see that file one has been created 27 00:01:19,950 --> 00:01:22,170 as it is right now on our desktop, 28 00:01:22,170 --> 00:01:26,370 since we created it inside of the slash desktop directory. 29 00:01:26,370 --> 00:01:29,730 And if we also type ls, we can see that the file 30 00:01:29,730 --> 00:01:32,190 is in our desktop directory. 31 00:01:32,190 --> 00:01:35,040 To make sure this file is indeed empty, 32 00:01:35,040 --> 00:01:37,680 we can use the command cat 33 00:01:37,680 --> 00:01:40,830 and this command, once executed on the file, 34 00:01:40,830 --> 00:01:45,450 writes out all the contents that are inside of that file. 35 00:01:45,450 --> 00:01:46,890 Let's try it out. 36 00:01:46,890 --> 00:01:50,373 So we specify cat and then file one, 37 00:01:52,080 --> 00:01:55,380 press enter, and this will give no results 38 00:01:55,380 --> 00:01:57,330 since as we already mentioned, 39 00:01:57,330 --> 00:02:00,960 the touch command creates empty files. 40 00:02:00,960 --> 00:02:02,430 If we want to, for example, 41 00:02:02,430 --> 00:02:04,230 put something inside of that file, 42 00:02:04,230 --> 00:02:06,870 we can use a command echo. 43 00:02:06,870 --> 00:02:09,539 You simply just type it like this, echo 44 00:02:09,539 --> 00:02:13,500 and to put something, you specify after the echo, 45 00:02:13,500 --> 00:02:18,500 let's say today is a really good day. 46 00:02:18,840 --> 00:02:21,960 So we specified an entire sentence 47 00:02:21,960 --> 00:02:22,950 and all we need to do 48 00:02:22,950 --> 00:02:25,410 to put this sentence inside of this file, 49 00:02:25,410 --> 00:02:27,940 is to specify this arrow to the right 50 00:02:28,980 --> 00:02:31,593 and after it specify the name of the file 51 00:02:31,593 --> 00:02:34,470 that we want to put this sentence in. 52 00:02:34,470 --> 00:02:36,870 So echo, today is a really good day, 53 00:02:36,870 --> 00:02:41,870 into the file one, press enter, and if we cat it once again, 54 00:02:43,290 --> 00:02:46,743 with the cat command, so cat file one. 55 00:02:48,360 --> 00:02:51,090 We will see that now it outputs exactly 56 00:02:51,090 --> 00:02:54,810 what we've written to that file, using the echo command. 57 00:02:54,810 --> 00:02:57,300 Okay, that's all good, but there is an easier way 58 00:02:57,300 --> 00:03:00,690 and more practical way to do all of this. 59 00:03:00,690 --> 00:03:02,130 We can use a text editor 60 00:03:02,130 --> 00:03:04,680 to write things inside of a file 61 00:03:04,680 --> 00:03:07,830 and an easy text editor that we can run from terminal 62 00:03:07,830 --> 00:03:09,630 is called nano. 63 00:03:09,630 --> 00:03:13,083 So let's try to do the same thing we just did using nano. 64 00:03:13,980 --> 00:03:16,830 If we type nano and after nano 65 00:03:16,830 --> 00:03:19,800 comes the name of the file that you want to edit, 66 00:03:19,800 --> 00:03:22,110 and since we want to edit a new file 67 00:03:22,110 --> 00:03:25,110 that we haven't created yet, we can simply just type name, 68 00:03:25,110 --> 00:03:28,590 let's call it file two and press enter. 69 00:03:28,590 --> 00:03:30,630 This will open this empty window 70 00:03:30,630 --> 00:03:33,150 where we can type anything we want. 71 00:03:33,150 --> 00:03:37,050 We can type file content here and it can be anything. 72 00:03:37,050 --> 00:03:39,030 We can type for example text here, 73 00:03:39,030 --> 00:03:42,420 but we could also type code if we wanted to. 74 00:03:42,420 --> 00:03:44,400 Let's start with text first. 75 00:03:44,400 --> 00:03:48,663 Let's write just Hello World as a text. 76 00:03:49,620 --> 00:03:54,620 To save this we press control O together, then enter to save 77 00:03:55,950 --> 00:04:00,183 under this name, and then control X to exit the nano editor. 78 00:04:01,140 --> 00:04:06,060 If we now type cat and then file two, and by the way, 79 00:04:06,060 --> 00:04:08,940 we can notice that file two has been created 80 00:04:08,940 --> 00:04:13,503 along file one on our desktop, but if we cat file two, 81 00:04:15,090 --> 00:04:18,153 we can see the output of Hello World. 82 00:04:19,050 --> 00:04:21,720 So we manage to do it only using one tool 83 00:04:21,720 --> 00:04:24,000 which is nano, instead of using two tools 84 00:04:24,000 --> 00:04:25,920 which are touch and echo, 85 00:04:25,920 --> 00:04:29,880 but I also mentioned we can do the same thing with programs. 86 00:04:29,880 --> 00:04:32,010 For example, how can we create 87 00:04:32,010 --> 00:04:35,400 Python program using nano and terminal? 88 00:04:35,400 --> 00:04:37,710 First we need to open a file. 89 00:04:37,710 --> 00:04:42,710 So let's type nano and then file three dot py. 90 00:04:43,230 --> 00:04:46,410 And in this case we add dot py, 91 00:04:46,410 --> 00:04:50,583 because that is an extension for Python programs. 92 00:04:51,720 --> 00:04:55,020 Then inside of it, after pressing enter, 93 00:04:55,020 --> 00:04:56,940 we're going to run a simple command 94 00:04:56,940 --> 00:05:01,940 which is print and then Hello World between the quotes 95 00:05:03,480 --> 00:05:07,140 and you will see that some stuff changes colors. 96 00:05:07,140 --> 00:05:10,710 This is because the nano editor recognizes this 97 00:05:10,710 --> 00:05:12,930 as a Python program. 98 00:05:12,930 --> 00:05:13,950 What we did right here, 99 00:05:13,950 --> 00:05:15,990 in case you're not familiar with Python, 100 00:05:15,990 --> 00:05:19,410 is we just ran a simple function that will print out 101 00:05:19,410 --> 00:05:22,590 the string that is in between the quotes. 102 00:05:22,590 --> 00:05:24,933 So this will just print out Hello World. 103 00:05:25,890 --> 00:05:28,830 Let's save it with control O, then press enter 104 00:05:28,830 --> 00:05:31,350 and then control X to exit. 105 00:05:31,350 --> 00:05:32,640 And luckily for us 106 00:05:32,640 --> 00:05:35,700 Python is already installed in Kali Linux. 107 00:05:35,700 --> 00:05:38,340 So all we need to do to run this program 108 00:05:38,340 --> 00:05:42,930 is to type Python three and then the name of the file, 109 00:05:42,930 --> 00:05:44,583 file three dot py, 110 00:05:45,420 --> 00:05:48,750 press enter and the program will execute. 111 00:05:48,750 --> 00:05:53,040 Here it printed out Hello World, cool right? 112 00:05:53,040 --> 00:05:54,840 You'll also notice that the icon 113 00:05:54,840 --> 00:05:58,500 is different than these two icons. 114 00:05:58,500 --> 00:06:00,060 This is also, once again, 115 00:06:00,060 --> 00:06:03,390 because this is recognized as a Python program, 116 00:06:03,390 --> 00:06:04,923 it even has the Python icon. 117 00:06:06,120 --> 00:06:08,880 Now that we know how to create files, 118 00:06:08,880 --> 00:06:12,480 and execute Python programs, the next question would be, 119 00:06:12,480 --> 00:06:15,210 how can we create directories. 120 00:06:15,210 --> 00:06:19,590 To create a directory, we can use the command mkdir, 121 00:06:19,590 --> 00:06:21,693 which stands for make directory. 122 00:06:22,860 --> 00:06:25,200 To check it out, let us run mkdir 123 00:06:25,200 --> 00:06:27,633 and name a directory folder. 124 00:06:28,620 --> 00:06:31,860 So press enter, and if I type ls, 125 00:06:31,860 --> 00:06:35,550 we will see that we got our files as well as a directory, 126 00:06:35,550 --> 00:06:38,823 which is different color and it is called folder. 127 00:06:39,750 --> 00:06:43,140 Remember we differentiate them by color and also 128 00:06:43,140 --> 00:06:47,220 if we try to change directory to the folder, it'll work. 129 00:06:47,220 --> 00:06:51,390 It'll even give us the path of slash desktop slash folder. 130 00:06:51,390 --> 00:06:53,940 Great, in that folder you can do pretty much 131 00:06:53,940 --> 00:06:55,140 anything you want. 132 00:06:55,140 --> 00:06:58,560 You can create sub folders or create files. 133 00:06:58,560 --> 00:07:01,260 Whatever you want to do, you can. 134 00:07:01,260 --> 00:07:04,020 To move for example, our Python program 135 00:07:04,020 --> 00:07:07,080 from the desktop directory to our folder directory, 136 00:07:07,080 --> 00:07:10,473 we can use command mv, which stands for move. 137 00:07:11,640 --> 00:07:13,860 We must first navigate back to desktop directory. 138 00:07:13,860 --> 00:07:15,390 So let's do it using cd 139 00:07:15,390 --> 00:07:18,630 and then two dots, to go one directory back. 140 00:07:18,630 --> 00:07:23,630 And from it we run the command mv, file three dot py, 141 00:07:24,810 --> 00:07:26,430 into the folder. 142 00:07:26,430 --> 00:07:28,230 So we specify and move. 143 00:07:28,230 --> 00:07:31,410 Then the second parameter is what we want to move 144 00:07:31,410 --> 00:07:33,600 which in our case is file three dot py. 145 00:07:33,600 --> 00:07:37,500 And the last parameter is where we want to move it. 146 00:07:37,500 --> 00:07:39,930 We want to move it inside of our folder, 147 00:07:39,930 --> 00:07:43,110 so press here enter, and you will notice 148 00:07:43,110 --> 00:07:45,930 that the file three dot py disappeared 149 00:07:45,930 --> 00:07:47,883 from our desktop directory. 150 00:07:48,720 --> 00:07:51,030 We can also check that by typing ls, 151 00:07:51,030 --> 00:07:55,230 and notice that our Python program is no longer here. 152 00:07:55,230 --> 00:07:59,100 But if we go to the folder directory and type ls here 153 00:07:59,100 --> 00:08:01,560 we will see it here because we moved it. 154 00:08:01,560 --> 00:08:05,220 Here it is file three dot py. 155 00:08:05,220 --> 00:08:08,790 Now this is a handy command and you will use it a lot. 156 00:08:08,790 --> 00:08:11,460 Besides moving the file, we also want to see, 157 00:08:11,460 --> 00:08:13,140 how we can copy a file 158 00:08:13,140 --> 00:08:16,023 and we can do it using the cp command. 159 00:08:16,950 --> 00:08:20,190 This does the exact same thing as move command, 160 00:08:20,190 --> 00:08:22,380 but it doesn't move it from original directory 161 00:08:22,380 --> 00:08:25,560 to desired directory, it just copies it. 162 00:08:25,560 --> 00:08:27,870 So let's try to copy file three dot py 163 00:08:27,870 --> 00:08:30,033 and call it file four dot py. 164 00:08:30,930 --> 00:08:35,409 If I typed cp, which stands for copy, file three dot py 165 00:08:36,720 --> 00:08:40,980 and I type file four dot py, right after it. 166 00:08:40,980 --> 00:08:42,929 This will create an exact copy 167 00:08:42,929 --> 00:08:45,720 of our file in the same directory. 168 00:08:45,720 --> 00:08:50,720 If I press enter and type ls, here it is, 169 00:08:50,790 --> 00:08:54,420 we got file three dot py and file four dot py. 170 00:08:54,420 --> 00:08:56,550 If you want change whether they're exactly the same 171 00:08:56,550 --> 00:08:59,700 we can cat the content of file three dot py, 172 00:08:59,700 --> 00:09:02,850 and cat the content of file four dot py. 173 00:09:02,850 --> 00:09:05,943 And we can see they're both the same Python programs. 174 00:09:07,230 --> 00:09:09,570 And last command that we want to cover 175 00:09:09,570 --> 00:09:12,513 regarding files is the command rm. 176 00:09:13,350 --> 00:09:15,960 This command deletes files and directories. 177 00:09:15,960 --> 00:09:19,410 And let's say we try to delete file four dot py. 178 00:09:19,410 --> 00:09:22,620 That is our copy of our Python program. 179 00:09:22,620 --> 00:09:27,540 We can do it by typing rm and then file four dot py. 180 00:09:27,540 --> 00:09:29,520 Now be careful with this command, 181 00:09:29,520 --> 00:09:31,500 since once you delete the file, 182 00:09:31,500 --> 00:09:33,870 there is no trash bin where you can retrieve it. 183 00:09:33,870 --> 00:09:34,953 It is gone. 184 00:09:35,850 --> 00:09:38,910 If I type enter and type ls, 185 00:09:38,910 --> 00:09:41,973 you will see our file four dot py is no longer there. 186 00:09:42,930 --> 00:09:45,573 Okay, but how do we delete a directory? 187 00:09:46,710 --> 00:09:48,270 Let's first create a directory 188 00:09:48,270 --> 00:09:50,430 inside of our folder directory. 189 00:09:50,430 --> 00:09:55,430 And to do that we type mkdir and let's call it folder two. 190 00:09:56,760 --> 00:09:59,910 Folder two is a sub directory of our folder. 191 00:09:59,910 --> 00:10:02,700 If I type ls, here it is. 192 00:10:02,700 --> 00:10:05,460 And let's say we did create this directory by mistake 193 00:10:05,460 --> 00:10:07,350 and we want to delete it. 194 00:10:07,350 --> 00:10:10,233 Can we use rm, folder two? 195 00:10:11,220 --> 00:10:12,723 Well, we can try it. 196 00:10:14,520 --> 00:10:17,850 Hmm cannot remove folder two and it will tell us 197 00:10:17,850 --> 00:10:19,740 that it is a directory. 198 00:10:19,740 --> 00:10:21,480 So how do we delete it? 199 00:10:21,480 --> 00:10:25,650 Well, we'll remove it in the same way we remove files. 200 00:10:25,650 --> 00:10:28,500 We just add an option at the end of the command. 201 00:10:28,500 --> 00:10:31,500 So type rm, folder two 202 00:10:31,500 --> 00:10:36,213 and then at the end add space and then dash r, 203 00:10:37,320 --> 00:10:40,653 press enter and this will delete our directory. 204 00:10:41,550 --> 00:10:43,710 Also, double check what you're deleting 205 00:10:43,710 --> 00:10:46,920 with this command since if you go to our slash directory, 206 00:10:46,920 --> 00:10:48,960 which is directory containing all folders 207 00:10:48,960 --> 00:10:50,370 and files in system, 208 00:10:50,370 --> 00:10:55,170 and if you were to type, for example, in that directory rm, 209 00:10:55,170 --> 00:10:59,850 then the star sign and then dash r, this command 210 00:10:59,850 --> 00:11:02,400 would delete entire Kali Linux machine 211 00:11:02,400 --> 00:11:04,440 with all of its files. 212 00:11:04,440 --> 00:11:06,150 So always pay attention 213 00:11:06,150 --> 00:11:08,190 what exactly are you deleting in Linux 214 00:11:08,190 --> 00:11:11,460 and from which directory are you deleting? 215 00:11:11,460 --> 00:11:12,960 Since inside of the Linux 216 00:11:12,960 --> 00:11:16,170 you will not be stopped in deleting anything you want. 217 00:11:16,170 --> 00:11:17,940 You can easily delete a crucial file 218 00:11:17,940 --> 00:11:19,500 for the operating system, 219 00:11:19,500 --> 00:11:22,410 and make your Kali Linux machine unworkable. 220 00:11:22,410 --> 00:11:24,600 That is also a reason why we are practicing 221 00:11:24,600 --> 00:11:25,743 with virtual machine. 222 00:11:26,820 --> 00:11:28,650 So let's, oops. 223 00:11:28,650 --> 00:11:31,110 I actually ran this and you will notice that the results 224 00:11:31,110 --> 00:11:32,970 of this command, if I type ls, 225 00:11:32,970 --> 00:11:35,760 now our folder is completely empty. 226 00:11:35,760 --> 00:11:39,570 So I actually ran this by mistake and keep in mind, 227 00:11:39,570 --> 00:11:41,940 if I actually ran this from the slash directory, 228 00:11:41,940 --> 00:11:43,620 which is our route directory, 229 00:11:43,620 --> 00:11:46,050 I will delete entire Kali Linux system. 230 00:11:46,050 --> 00:11:47,310 For now on, it is good 231 00:11:47,310 --> 00:11:49,380 since I only deleted our Python program 232 00:11:49,380 --> 00:11:51,300 so it is not a big deal. 233 00:11:51,300 --> 00:11:52,440 Okay, great. 234 00:11:52,440 --> 00:11:54,960 We learn bunch of the commands in this lecture. 235 00:11:54,960 --> 00:11:57,060 Now I got the practice test for you 236 00:11:57,060 --> 00:12:00,150 that you can try to do for the next lecture. 237 00:12:00,150 --> 00:12:01,770 Inside of our folder directory, 238 00:12:01,770 --> 00:12:04,050 since I deleted my Python program, 239 00:12:04,050 --> 00:12:07,560 I want you to create the file three dot py, once again, 240 00:12:07,560 --> 00:12:09,780 you can type anything you want inside of it. 241 00:12:09,780 --> 00:12:12,990 You can use the print Hello World statement that we used. 242 00:12:12,990 --> 00:12:15,750 And what I want you to do using the commands you learned 243 00:12:15,750 --> 00:12:18,990 in this video is to copy that file 244 00:12:18,990 --> 00:12:22,440 in the desktop directory from our folder directory. 245 00:12:22,440 --> 00:12:24,510 So you create it inside of this directory 246 00:12:24,510 --> 00:12:28,293 and I want you to copy back to the desktop directory. 247 00:12:29,160 --> 00:12:31,860 A hint is that it can be a little tricky, 248 00:12:31,860 --> 00:12:34,860 once you copy file from some directory to directory. 249 00:12:34,860 --> 00:12:36,240 Anyways, just try it, 250 00:12:36,240 --> 00:12:39,273 and we're going to see the solution in the next video.