WEBVTT 00:05.800 --> 00:12.160 In this video you're going to continue with the E grep command which will allow you to search a certain 00:12.160 --> 00:16.220 file and find lines containing one word or the other. 00:16.420 --> 00:23.470 So the syntax is this one and make sure you use quotes when using this command. 00:23.500 --> 00:32.680 So let's try this so let's try this on scripts those days. 00:33.880 --> 00:39.170 So let's look for high or go like this 00:43.600 --> 00:50.500 and here we go you can see you've got lines containing either high or goal. 00:50.510 --> 00:55.790 Now let's see if we had a line containing both golf and high and see 00:59.050 --> 01:00.970 if he's gonna show up. 01:01.000 --> 01:02.380 Yes it does. 01:02.390 --> 01:02.650 All right. 01:02.650 --> 01:08.510 So this command will return all lines containing either high goal or both. 01:09.340 --> 01:13.050 All right so let's move to the next example. 01:13.360 --> 01:21.620 Now let's look for lines containing a certain word but not another word. 01:22.430 --> 01:30.050 So for this we're gonna use typing so we get the results first for the first word and then we run the 01:30.080 --> 01:35.030 grip minus B command on the results. 01:35.300 --> 01:37.100 So let's say that we want to 01:41.080 --> 01:41.950 look for lines 01:44.810 --> 01:49.680 containing goals but not containing high. 01:51.010 --> 01:51.430 So 01:55.710 --> 02:06.110 this command will give us all lines containing goal and then we use the grip minus B command with high 02:08.400 --> 02:16.970 to return all lines most containing high and we get only one line which is this one containing gold 02:17.360 --> 02:20.360 but not containing high. 02:20.400 --> 02:22.600 All right. 02:22.740 --> 02:24.990 Now let's move to the next one. 02:24.990 --> 02:34.050 Now we want to look recursively for files only files not folders with a name matching a certain pattern 02:34.950 --> 02:38.270 inside our folder note. 02:38.790 --> 02:42.550 So we're going to use the find command. 02:42.600 --> 02:48.780 So if you run the command inside the file that note then the first primary. 02:48.780 --> 02:51.150 So you need to pass to the command is the location. 02:51.150 --> 02:59.440 So we gonna use dots for current location and then we're going to use an option name to specify what 02:59.440 --> 03:06.450 s pattern the name of our files should match or verify. 03:06.450 --> 03:14.110 And then we are going to use the type option to make sure that we get only files not for this. 03:14.800 --> 03:17.100 So let's try this command. 03:18.490 --> 03:30.450 So let's say that we want to look for files Starting with S C so find. 03:30.450 --> 03:36.850 So let's see where we are at the moment so let's move up one directory. 03:37.060 --> 03:38.460 We are inside node. 03:38.830 --> 03:48.020 So now find dots meaning in any current location and then we're looking for 03:50.780 --> 03:55.660 all files starting with C so C and then start 03:58.890 --> 04:04.210 we're going to use the name option right before this 04:07.390 --> 04:14.120 and then we gonna use the type option it to f meaning we looking for files. 04:14.380 --> 04:17.300 So let's try this. 04:17.420 --> 04:24.140 So here are the files verifying those conditions. 04:24.670 --> 04:24.970 Okay. 04:24.990 --> 04:28.290 So that's how you use the find command. 04:28.290 --> 04:31.220 Now let's move to the next example. 04:31.380 --> 04:35.220 So this time we're looking for folders. 04:35.220 --> 04:40.380 So we want early folders verifying with a name verifying SS in person. 04:40.650 --> 04:44.130 So instead of type f we going to use Type D by the way. 04:44.130 --> 04:48.830 You can also use control L to wipe the contents of your terminal. 04:48.900 --> 04:55.230 So before going ahead I'm going to change the name of Jesus to do something else. 04:56.500 --> 05:00.220 So let's call it javascript 05:03.860 --> 05:16.360 and let's say that we want to look for files in the current location with a name matching this pattern. 05:16.880 --> 05:21.490 So starting with Jess OK. 05:21.520 --> 05:24.870 So we're looking for for this. 05:24.880 --> 05:31.720 So type D and who we go only that file verifies this condition. 05:31.900 --> 05:42.610 Now let's try something else and look for all for this starting with SC and since our search is recursive 05:42.940 --> 05:48.990 using the find command it will look inside some folders as well. 05:48.990 --> 05:51.240 So that's the that's wonderful They're verifying that. 05:51.240 --> 05:54.160 And that's another one. 05:54.190 --> 05:54.490 All right. 05:54.490 --> 05:54.940 Perfect. 06:00.070 --> 06:03.920 So let's move to the next example. 06:04.500 --> 06:12.960 Now we want to look recursively for folders with a name matching a person. 06:13.080 --> 06:19.330 And then once we find those folders we want to delete them. 06:19.370 --> 06:31.100 So to do this you can add an option gold exec so following this option you can run a command on the 06:31.100 --> 06:34.410 outputs of the previous command. 06:34.430 --> 06:43.950 So this means that whatever you find using this command you're on this command on its all right. 06:44.000 --> 06:49.860 All right so let's find inside the current location. 06:49.890 --> 06:55.320 All files with a name matching this pattern. 06:55.500 --> 07:10.060 So let's find all files ending with or folders ending with scripts so we are interested in folders only. 07:10.160 --> 07:19.990 So you gonna set the type property to D and then we're going to execute a command on those files so 07:19.990 --> 07:21.890 we want to remove those files. 07:21.970 --> 07:31.600 So if you remember the command is arm with an option and an option F and then at the end you just add 07:32.440 --> 07:43.720 curly brackets like this inside quotes and then a backslash like this and then semicolon. 07:43.780 --> 07:56.200 So if we run on this name you're supposed to find all files or All Folders ending with scripts and deleting 07:56.200 --> 07:57.520 them. 07:57.520 --> 08:02.590 So we want fall is ending with scripts. 08:02.610 --> 08:07.260 So the name should start with a star that ends with script. 08:07.680 --> 08:11.670 So let's try this. 08:11.900 --> 08:13.500 All right. 08:13.490 --> 08:20.820 So this deleted the javascript folder with everything inside it. 08:20.910 --> 08:28.080 We left early with the James folder and its files and this and we getting an error here. 08:28.120 --> 08:29.860 No such file or directory. 08:29.860 --> 08:33.550 You don't have to worry about this one. 08:34.430 --> 08:39.530 Okay so now let's move to the next one. 08:43.750 --> 08:50.490 So this time we want to get the size of a certain folder. 08:51.340 --> 08:57.430 So we are gonna be inside the file that node and we gonna get it site. 08:57.440 --> 09:07.660 So first of all let's try this command and see what we get so the command is due and the options we're 09:07.660 --> 09:18.400 going to pass through is our C and H and the location we are referring to here is where we are which 09:18.400 --> 09:19.350 is the current location. 09:19.710 --> 09:21.160 So let's try this. 09:21.160 --> 09:30.010 So this is returning the sizes of different files and folders which are inside 09:33.190 --> 09:36.690 for the note so. 09:37.060 --> 09:39.060 And at the end you can see the total. 09:39.280 --> 09:46.750 And this is the sum of all the different sizes. 09:47.500 --> 09:51.600 So we are interested in the total only. 09:51.610 --> 09:57.130 So to to do this we can get the outputs of this command. 09:57.160 --> 10:07.410 So I'm gonna use the up arrow and then I'm gonna use piping and then I'm going to grep total. 10:07.480 --> 10:15.890 So this line contains total so it should return that line for us all right. 10:15.900 --> 10:20.130 That's a an easy way to get to the size of a certain folder. 10:20.640 --> 10:23.430 So bear in mind that we did this inside node. 10:23.550 --> 10:31.300 If you do this outside node then you can use the full path of node or a relative path. 10:31.580 --> 10:33.660 OK so let's move to something else 10:40.820 --> 10:48.930 now if you want to find in which location you've got an executable file like node you just use the which 10:48.940 --> 10:49.330 command 10:52.920 --> 10:57.330 and if you remember this is where our node executable is. 10:57.390 --> 11:07.620 So I can try that with NPM as well and I can try that with brackets as well as I've got the terminal 11:07.650 --> 11:10.320 utility for brackets. 11:10.330 --> 11:11.990 Perfect. 11:12.600 --> 11:15.140 So control l uh. 11:15.330 --> 11:16.860 Let's move to the next one. 11:17.070 --> 11:23.790 So in this example you're going to replace all occurrences of a certain word in your file with another 11:23.790 --> 11:24.590 word. 11:25.260 --> 11:28.260 So to do this you're going to use the said command. 11:28.260 --> 11:34.630 So this command will take as an option minus I followed by an extension. 11:34.650 --> 11:35.590 Thus you choose. 11:35.640 --> 11:38.940 So I chose the extension dots back backup. 11:38.940 --> 11:41.300 You can choose any extension you like. 11:41.400 --> 11:46.860 So this extension is gonna be used to create a backup file of your original file. 11:46.950 --> 11:53.730 So if the cut your file is called up or Jesus and you use that extension then the backup file is going 11:53.730 --> 12:06.200 to be called up DOJ as those backup and then you place inside double quotes or inside quotes. 12:06.200 --> 12:15.850 As for substitute for large force large G for global to replace all occurrences so that's why you use 12:15.850 --> 12:16.750 G. 12:17.130 --> 12:24.310 And then in between you place your word to be replaced and then the word which is gonna replace all 12:24.400 --> 12:25.850 occurrences. 12:25.990 --> 12:28.200 So let's go ahead and try this. 12:28.900 --> 12:29.440 So 12:34.320 --> 12:44.280 let's use the AI option and I'm gonna go for backup as an extension of then as for Slash force slash 12:44.960 --> 12:45.670 G. 12:45.860 --> 12:48.390 So substitutes and global. 12:48.390 --> 12:52.680 And then I want to replace all occurrences of high for example 12:55.570 --> 13:05.260 with Hiba and the file I'm looking at is the script though J as while so the moments inside. 13:05.330 --> 13:09.820 Note so I need to go inside the j s folder 13:14.390 --> 13:20.560 so let's try this and you can see that we of course a backup file there which is a copy of the original 13:20.560 --> 13:20.920 file 13:24.270 --> 13:30.660 and you can see that all occurrences of high have been changed to high the perfect 13:37.110 --> 13:38.880 so let's move to the next. 13:38.880 --> 13:45.090 So in this example you're going to download a file from the Internet using the command line. 13:45.750 --> 13:53.330 So to do this you need the W get command so first you will need to install this command on your system 13:53.600 --> 14:01.850 so you can use homebrew to do that by copying these two commands so you can find them in the presentation 14:02.270 --> 14:06.480 which is gonna be included in the documentation of the course. 14:06.530 --> 14:14.450 So once you do that you just type w get space followed by the arrival of the file you would like to 14:14.510 --> 14:16.350 download. 14:16.590 --> 14:17.760 So let's try this 14:20.730 --> 14:24.880 so I'm going to copy the URL of this image 14:28.600 --> 14:33.710 and I'm going to use that would you get space. 14:33.860 --> 14:42.000 You know now I can see that the image has been downloaded into my node folder. 14:42.470 --> 14:45.030 All right now let's move to the next example. 14:45.050 --> 14:49.940 So now you're going to create a buzz scripts and run it. 14:49.940 --> 14:56.020 So this is going to be an executable file which you will create on your computer and make it a click 14:56.030 --> 15:02.560 executable and then run it after writing some bash code in it. 15:03.960 --> 15:07.410 So I'm going to explain what's bad securities. 15:07.680 --> 15:19.780 So first we're going to create the file touch file name and then you you would add the execution permission 15:19.960 --> 15:20.590 to all the users. 15:20.620 --> 15:28.820 So if you don't specify the type of user then plus X means that's you adding execution to all types 15:28.820 --> 15:33.130 of users and then the file name. 15:33.410 --> 15:42.110 And then after writing code inside the file to execute it it's dot for slice your file if you are in 15:42.110 --> 15:48.500 the same location or the same folder where the file is located. 15:48.500 --> 15:50.310 All right so let's go ahead and do this. 15:51.450 --> 16:01.420 So I'm currently in the node folder so let's create our file run so let's make it executable. 16:01.480 --> 16:15.560 So change mode plus X of run and now let's open the file in brackets and write some code. 16:15.580 --> 16:22.780 Now the first line will need to specify where the Bosch executable is. 16:22.810 --> 16:28.780 So we're going to use which bash to see where it is. 16:28.780 --> 16:38.680 So that's the location where our executable file is so you you need to write a number sign like this 16:39.980 --> 16:40.760 followed by 16:43.500 --> 16:44.860 exclamation mark. 16:45.120 --> 16:48.200 And then the location of. 16:48.210 --> 16:52.290 BASH So let's say that's going to rise. 16:52.530 --> 17:01.020 A simple script which will create a file and then inside this file we're going to place or combine the 17:01.020 --> 17:07.260 contents of all these files located inside the James folder. 17:07.260 --> 17:16.650 So let's create our file and call it all those days and then we're going to loop through the files inside 17:16.740 --> 17:17.970 the data folder. 17:17.970 --> 17:21.630 So as you do this you're gonna need a for loop. 17:21.630 --> 17:26.070 So for file in PJ It's folder. 17:26.070 --> 17:29.220 So you want only the James Files. 17:29.220 --> 17:33.240 So there's gonna be files matching 17:35.960 --> 17:36.740 the following 17:41.810 --> 17:53.860 button and then semicolon do and then at the end we're going to have done so here. 17:53.870 --> 17:55.540 You can write all the commands you want. 17:55.540 --> 17:58.970 So for example Let's echo the name of each file. 17:59.120 --> 18:06.100 So you gonna use the file variable inside double quotes. 18:06.110 --> 18:16.190 You use a dollar sign followed by the name of the variable and then we want to append the contents of 18:16.190 --> 18:24.290 that file to all those deaths so to do this we gonna read the file 18:30.300 --> 18:38.720 and then we're going to use double grid then sign to append and append to all the objects. 18:38.730 --> 18:41.590 Okay so let's say this. 18:41.610 --> 18:42.930 Let's run our file 18:48.700 --> 18:51.450 so you can see the names of the files. 18:51.490 --> 18:52.050 Right. 18:52.060 --> 18:55.090 That's the first command and let's check all. 18:55.920 --> 19:02.340 And you can see that we have appended the contents of both the script dodgy as file army server logic 19:02.400 --> 19:04.990 while all right. 19:04.990 --> 19:11.410 So hopefully this command line Crash Course gave you a good understanding of the command line. 19:11.440 --> 19:14.080 So in the next video you're going to go back to note.