WEBVTT 00:05.640 --> 00:10.770 In this video you're going to continue file manipulation in the command line crash course. 00:11.250 --> 00:18.830 So this time you're going to check a few commands which will help you read files. 00:19.080 --> 00:27.470 So the cuts command will help you read a certain file the vim command can do that as well. 00:27.490 --> 00:28.480 They're a bit different. 00:28.510 --> 00:30.550 They both come with different features. 00:30.640 --> 00:32.950 So let's try the card's command first 00:37.020 --> 00:41.750 so at the moment we are inside James. 00:41.820 --> 00:53.330 So let's read scripts both James. 00:53.450 --> 00:54.710 All right. 00:55.040 --> 00:57.660 You can add some options to cut. 00:57.680 --> 01:08.190 So for example the end option will output the line numbers you can see the line numbers that now you 01:08.200 --> 01:14.480 can do the same thing with vim. 01:14.980 --> 01:16.120 And if you 01:18.850 --> 01:29.330 press eye then you can edit the file on your characters remove characters etc. and you can navigate 01:29.450 --> 01:32.860 using the arrow buttons. 01:32.900 --> 01:34.730 So for example I can add a new line 01:38.990 --> 01:42.420 like this and to save. 01:42.560 --> 01:49.710 I'm gonna press escape and make along for right and then q to quit. 01:52.690 --> 01:53.430 All right. 01:53.720 --> 02:01.820 So that's regarding cuts and VIM so you can explore these two commands using the manual you can check 02:01.820 --> 02:05.150 the different features that they both have. 02:05.180 --> 02:08.380 There is another command you can use which is unique. 02:08.540 --> 02:19.040 And this one will just print unique lines without any duplicates. 02:19.320 --> 02:26.880 So instead of printing this line twice it is printed only once because we are using the unique command. 02:26.910 --> 02:27.180 All right. 02:27.210 --> 02:36.500 So the next one you can print only the first and lines of a certain files or the last. 02:36.510 --> 02:43.350 And lines or face or some file using the head and tail commands oh let's try head and tail on our script. 02:43.370 --> 02:44.240 Got a smile. 02:44.280 --> 02:48.840 So first let's add some more content to our file 02:54.000 --> 02:59.460 so let's display the first four lines. 03:04.150 --> 03:08.030 Scripts thought Jasmine and here we go. 03:08.050 --> 03:13.410 Now let's display the last five lines 03:18.280 --> 03:24.810 and here you go. 03:24.980 --> 03:29.900 So the reason why we see this is because there is no line return there. 03:30.020 --> 03:30.770 So let's try again 03:34.400 --> 03:36.850 and that looks better. 03:36.850 --> 03:38.510 There is another syntax. 03:38.510 --> 03:39.570 You can. 03:39.620 --> 03:40.520 Instead of minus five. 03:40.520 --> 03:47.300 You can write minus one and then space the number you want OK. 03:47.300 --> 03:48.980 So now let's move to the next example 03:53.720 --> 03:57.990 now gets introduced to the piping concept. 03:58.610 --> 04:08.920 So the piping concept is when you use the output of a certain command as the input of another command. 04:08.930 --> 04:16.840 So here we are trying to print row three of our file server nowadays or opt for James. 04:17.540 --> 04:26.030 So first we're going to print the first three lines and then out with those three lines we're going 04:26.030 --> 04:28.380 to print the last line. 04:28.910 --> 04:35.470 So head minus three print the first three lines of our file and then tail minus one. 04:35.480 --> 04:41.330 We'll print the last line of those three lines and that will give us the row three. 04:42.440 --> 04:43.370 So let's try this 04:47.710 --> 05:01.000 so had minus three of scripts nowadays and then the pipe symbol is this one. 05:01.160 --> 05:02.330 This is a vertical line 05:05.040 --> 05:14.090 so this is supposed to be next to to your enter button on the right hand side of your keyboard using 05:14.090 --> 05:14.780 a Mac 05:17.660 --> 05:23.590 if you're using a Windows machine then this is supposed to be on the left hand side and right next to 05:23.590 --> 05:26.800 your enter button. 05:26.830 --> 05:33.250 So now the outputs of this command is gonna be used as the inputs of the next command which is tail 05:34.280 --> 05:35.210 minus one. 05:35.980 --> 05:37.150 And now we're gonna be printing. 05:37.180 --> 05:38.100 Line number three. 05:38.710 --> 05:39.760 And here we go. 05:39.760 --> 05:42.310 That's line the misery. 05:43.020 --> 05:55.870 OK so let's move to the next one now you can't actually print lines of your boss history so the history 05:55.870 --> 06:02.440 contains the different commands which you have run on your terminal. 06:02.440 --> 06:11.230 So if you want the last three lines then you just type history which outputs all the lines so you don't 06:11.230 --> 06:15.980 want to show all the lines which are stored in the memory of your computer. 06:16.130 --> 06:18.580 But you want to show only a few ones. 06:18.580 --> 06:21.930 So in this example we're gonna show the last 20 lines. 06:22.960 --> 06:36.170 So history and then the pipe symbol vertical line and then the last 20 lines or minus 20. 06:36.170 --> 06:41.650 And this gives me the different commands as I have run so far. 06:41.650 --> 06:46.880 So these are the last 20 commands in my terminal history. 06:47.030 --> 06:47.500 All right. 06:47.500 --> 06:49.150 So the next one. 06:49.690 --> 06:56.790 So let's look for lines including the word helo inside our file upload J.S. or server dodges. 06:57.040 --> 07:03.370 So to do this we use the grep command so the grep command is a very useful command which will help you 07:03.370 --> 07:04.780 search files. 07:05.000 --> 07:08.180 Let's try it when our scripts those days file. 07:08.290 --> 07:09.800 So let's look for. 07:09.940 --> 07:13.960 Hello inside our file scripts. 07:13.960 --> 07:17.970 Those checks now you don't need to use quotes. 07:18.100 --> 07:20.290 It works fine with those. 07:20.350 --> 07:21.940 So here we go. 07:21.940 --> 07:31.920 So these are all the lines which contain hello inside our file scripts today's. 07:32.080 --> 07:42.920 Now you can add some options to your command so you can make the command case insensitive using minus 07:42.920 --> 07:49.810 I you can display lines using minus and display line numbers. 07:50.270 --> 07:53.300 You can highlight matching words using the color 07:56.020 --> 08:03.620 option with double minus sign and you can also look for lines excluding ISIS in weight using minus V. 08:03.670 --> 08:05.440 So let's try these. 08:05.710 --> 08:07.750 So now if I try to look for 08:14.520 --> 08:24.890 hello inside our file like this then it's not gonna return that line because hello there is written 08:24.910 --> 08:26.260 with capital letters. 08:26.300 --> 08:32.830 What if I tried the same thing with minus I then the surge is going to be case insensitive and he's 08:32.830 --> 08:35.500 going to show that line as well. 08:35.880 --> 08:50.270 So the next one is when you add the end command the an option like that's all like that s you can combine 08:50.270 --> 08:51.530 them like this. 08:51.530 --> 08:58.460 So this will Prince the line them is now you can also add 09:01.280 --> 09:09.500 color option and you'll see the matching words highlighted. 09:09.500 --> 09:20.280 And finally if you want to look for lines which do not contain the word hello that you use minus V 09:23.340 --> 09:29.990 and here you can get all the lines which do not include the word hello. 09:30.160 --> 09:31.290 Perfect. 09:32.170 --> 09:36.410 So now let's move to the next one. 09:36.630 --> 09:43.560 Now let's look for the first two lines including the word hello inside our file up DOJ us or server 09:43.950 --> 09:45.480 or scripts nowadays. 09:45.780 --> 09:49.350 So to do this use the option minus M 09:52.250 --> 09:56.360 so let's use a previous command 09:59.220 --> 10:01.990 and use minus m 2. 10:02.340 --> 10:11.110 So it is time we get only the first two lines and there is another way for that you can actually print 10:11.500 --> 10:20.100 your file and then use the output of that file as the input of your grep command. 10:20.140 --> 10:25.150 So basically you can do this with all grep commands. 10:25.150 --> 10:30.690 So there is it works is that following so cut off script the J. 10:30.700 --> 10:38.320 And then the outputs can be used as the inputs of grep when it's up to 10:41.400 --> 10:42.090 oh hello 10:46.190 --> 10:46.920 all right. 10:47.180 --> 10:48.640 So now let's move to the next one. 10:53.100 --> 11:00.660 Now when using the grep command you can actually search inside multiple files. 11:00.660 --> 11:07.050 So for example you can search all files ending dots DHS using a regular expression like this. 11:07.050 --> 11:19.660 So Star stands for any text than those J.S. means that's you're looking for files with a name text not 11:19.720 --> 11:21.680 any text those days. 11:21.700 --> 11:26.920 So this will look for all lines containing helo inside those files. 11:27.880 --> 11:29.310 So just try this. 11:29.360 --> 11:30.610 So at the moment we've got 11:35.230 --> 11:37.680 a couple of files inside our James wala. 11:38.080 --> 11:38.360 Right. 11:39.220 --> 11:45.930 So let's copy some contents from script to server not James. 11:45.980 --> 11:47.860 Now let's search all files 11:53.920 --> 11:55.210 ending those Jess 11:59.970 --> 12:02.600 and you can see that's the lines now. 12:02.610 --> 12:05.450 They contain the names of our files. 12:05.930 --> 12:09.440 So inside scripts though Jess we found all those lines. 12:09.630 --> 12:13.750 And then inside server though James we found all those lines. 12:13.800 --> 12:23.260 So that's how you can search multiple lines for a specific or multiple files for a specific with all 12:23.310 --> 12:23.530 right. 12:23.530 --> 12:27.770 So next one. 12:27.860 --> 12:34.840 Now let's look for lines including a certain button inside a file. 12:35.090 --> 12:42.330 So instead of looking for helo you can look for a certain pattern like this one. 12:42.330 --> 12:54.390 So that's age followed by any text followed by oh so let's try something like That's so grep for example 12:57.210 --> 12:57.740 J. 12:57.850 --> 13:01.990 Or D then store 13:11.640 --> 13:14.560 inside scripts. 13:14.590 --> 13:15.200 No Jess 13:18.570 --> 13:19.030 all right. 13:19.030 --> 13:24.210 Uh let's add a line here saying 13:29.610 --> 13:30.050 go 13:33.090 --> 13:34.830 I uh let's find another one. 13:36.070 --> 13:36.580 Saying 13:41.020 --> 13:41.650 get up 13:46.960 --> 13:51.250 so you can see there's all these lines are a match. 13:51.280 --> 13:59.900 So this one is a match because it contains G followed by some text and then I. 13:59.990 --> 14:09.780 Same for all those three and then GetUp is a match because that's g followed by some text that's empty 14:09.790 --> 14:12.460 and then I. 14:12.990 --> 14:21.710 And this one is not actually a much because I he has copies all so if I tried these same command with 14:21.710 --> 14:30.200 minus I to make this search insensitive then we should see that line as well. 14:30.200 --> 14:30.590 All right 14:33.890 --> 14:37.780 so let's move to the next example. 14:38.010 --> 14:47.080 Now we want to look for a certain word recruit recursively inside files located in a certain folder. 14:47.790 --> 14:54.900 So to do this you use the r option all right. 14:56.610 --> 15:00.950 So let's go to our node folder. 15:01.560 --> 15:05.240 At the moment we are inside the Janus folder. 15:05.280 --> 15:13.210 So let's move up one directories and now we are inside node and now we're gonna look recursively for 15:13.240 --> 15:14.520 the word hello. 15:14.560 --> 15:19.550 So this will search everything inside the node folder all right 15:25.490 --> 15:29.960 so it's odd a couple of lines here saying hello 15:35.510 --> 15:36.370 let's test this. 15:36.800 --> 15:39.230 So grip minus all 15:42.230 --> 15:49.440 the word hello and then we are looking inside this location. 15:49.440 --> 15:51.410 So that's how you use this. 15:51.420 --> 15:51.910 Come on. 15:51.910 --> 15:53.670 That's obviously the syntax for it. 15:54.330 --> 16:01.690 So now it's going to search everything inside the node for there. 16:01.990 --> 16:07.930 And I can see the results sir we've got inside the James folder we've got this file and that's the corresponding 16:07.930 --> 16:08.310 line. 16:09.460 --> 16:14.230 And then we've got that line inside that file inside that folder and so on. 16:14.260 --> 16:27.500 So it looked for all helo work words inside all files located inside node and it's stuff all this. 16:27.550 --> 16:28.490 All right. 16:28.730 --> 16:31.430 So let's check something else. 16:33.260 --> 16:41.150 Now let's look for helo recursively inside files located inside our for the node and instead of returning 16:41.150 --> 16:49.380 the lines we want to return only file names so as you do this we just add the L command. 16:49.660 --> 16:59.680 So instead of minus all you can write minus all minus L or combine them like this minus Ah hell. 16:59.710 --> 17:08.510 So this will tell us all the files where we found a much greats next one. 17:08.570 --> 17:11.800 Let's look for lines containing two words. 17:11.810 --> 17:19.490 So we want both Halo and console inside a certain file so you can use piping for that. 17:19.580 --> 17:25.880 Basically you look for the first word you get all lines containing that word and then you check those 17:25.880 --> 17:29.860 lines and see which ones contain that word as well. 17:29.870 --> 17:30.620 All right. 17:30.740 --> 17:44.510 So yes let's try that so let's try that on server though Jess and let's add a line with Halo early and 17:44.510 --> 17:46.560 another one with console. 17:47.840 --> 17:50.710 So we are inside node. 17:50.840 --> 17:54.080 Let's move to James. 17:54.320 --> 18:00.580 So we are inside James now and we're looking arts server those. 18:01.550 --> 18:11.320 So first let's look for the word hello inside server does James. 18:11.630 --> 18:18.450 And then we're going to use piping to use the outputs of this command as the inputs of the next command 18:18.480 --> 18:20.520 which will look for console 18:23.470 --> 18:23.920 like this 18:27.150 --> 18:37.240 Sarah let's try this so these are the lines which contain both Halo and console inside our file so you 18:37.240 --> 18:39.440 don't see that one because it contains only Hello. 18:39.560 --> 18:43.960 I don't see that line because it contains only console. 18:43.960 --> 18:46.970 All right so let's move to the next one. 18:47.320 --> 18:53.250 Now we're looking for lines containing either Hello or Hi. 18:53.340 --> 18:54.050 So hello. 18:54.160 --> 18:54.580 Oh hi 18:57.660 --> 18:59.160 or both. 18:59.160 --> 18:59.460 All right. 18:59.460 --> 19:00.960 Both will work as well. 19:00.990 --> 19:07.250 So to do this you can use the E grep command and we will continue this in the next video.