1 00:00:00,450 --> 00:00:09,300 Hello everyone in this is with you I'll show you how to execute multiple Linux commands in a single 2 00:00:09,300 --> 00:00:15,360 line and I will show you how to accomplish this using two different methods. 3 00:00:15,360 --> 00:00:17,120 So let's get started. 4 00:00:17,130 --> 00:00:25,620 So here I am on my desktop as you can see and if I type my date command and I think muted it will show 5 00:00:25,620 --> 00:00:30,990 me the date as you know from before and if I type the call command and execute it it will show me the 6 00:00:30,990 --> 00:00:32,070 calendar. 7 00:00:32,070 --> 00:00:36,720 So so far we have been executing our commands one at a time as you can see. 8 00:00:36,720 --> 00:00:41,240 So here I am securing my commands one at a time. 9 00:00:41,250 --> 00:00:46,980 However you can execute multiple commands at the same time. 10 00:00:47,010 --> 00:00:49,720 So how can we do this. 11 00:00:49,740 --> 00:00:56,640 So here we are going to explain the first method which is called the semi call mastered. 12 00:00:56,670 --> 00:01:04,230 So in general you can execute your first command and then you separated by a semicolon here your second 13 00:01:04,230 --> 00:01:09,240 command semi colon and then cetera blah blah blah. 14 00:01:09,360 --> 00:01:11,600 It will be your answer command. 15 00:01:12,440 --> 00:01:19,310 Oh this is the general format if you want to execute multiple commands. 16 00:01:19,310 --> 00:01:21,160 In this case we have any commands. 17 00:01:21,160 --> 00:01:28,800 At the same time using the semicolon mentioned So let's so let's examine this. 18 00:01:28,820 --> 00:01:32,870 So if I type a date in my colon calender 19 00:01:35,480 --> 00:01:39,620 as you can see this will show me the date and the calendar. 20 00:01:39,620 --> 00:01:41,400 All at once. 21 00:01:41,780 --> 00:01:47,690 So the colon is basically the same thing with using programming languages. 22 00:01:47,720 --> 00:01:54,860 So if you know C++ you would know that after lie after you're done with your statement you have to put 23 00:01:54,860 --> 00:01:55,920 a semi-colon. 24 00:01:56,030 --> 00:02:01,540 Basically it's called Like a statement separator so in C++ you can say something like this. 25 00:02:01,610 --> 00:02:06,740 You can say interger x is equal to three and then semi-colon. 26 00:02:07,130 --> 00:02:11,860 And to your Y is equal to for my colon. 27 00:02:11,990 --> 00:02:16,010 So this is valid in C++ and the same thing applies here. 28 00:02:16,160 --> 00:02:22,910 You can have multiple statements on the same line in C++ and also you can have multiple command on the 29 00:02:22,910 --> 00:02:25,880 same line in Linux. 30 00:02:26,150 --> 00:02:30,440 OK Arsen So let's get a more advanced here. 31 00:02:30,530 --> 00:02:37,040 So if I type make directory numbers then date and then calendar. 32 00:02:37,290 --> 00:02:43,560 This will first make a directory called numbers and then it'll show me the date and then it will show 33 00:02:43,560 --> 00:02:44,380 me the calendar. 34 00:02:44,400 --> 00:02:47,090 And you have to know that the ordering matters to you. 35 00:02:47,550 --> 00:02:55,290 So first I have my other my numbers directory then it shows me the data then it shows me the calendar. 36 00:02:55,460 --> 00:02:56,220 OK. 37 00:02:56,610 --> 00:03:05,440 And the order matters so if you say date to my colon calendar this will show you that the date first 38 00:03:05,440 --> 00:03:06,610 and then the calendar. 39 00:03:06,610 --> 00:03:14,620 However if you say calendar say my column date it will show you the calendar first and then it will 40 00:03:14,620 --> 00:03:15,730 show you the date. 41 00:03:15,730 --> 00:03:17,800 So here the order matters. 42 00:03:18,310 --> 00:03:26,200 OK you also have to know one thing when using the semicolon method the semi-colon method ignores all 43 00:03:26,230 --> 00:03:32,370 incorrect commands or it actually ignores all typos and errors. 44 00:03:32,380 --> 00:03:34,190 So what do I mean by that. 45 00:03:34,210 --> 00:03:40,630 So if you say call an uppercase C L you know that this this one is non-valid right. 46 00:03:40,630 --> 00:03:41,710 Command not found. 47 00:03:41,710 --> 00:03:44,250 Because our Linux commands are case sensitive. 48 00:03:44,440 --> 00:03:52,040 However if you say that then semi-colon date it will still show you the date so it will tell you. 49 00:03:52,090 --> 00:03:56,890 Command not found for calendar but I will still show you the date. 50 00:03:56,950 --> 00:04:01,480 So as you can see using a semi colon it actually ignores all the arrows. 51 00:04:01,510 --> 00:04:02,350 Right. 52 00:04:02,800 --> 00:04:07,450 It will only only show you or it will only execute the correct command. 53 00:04:07,440 --> 00:04:09,810 So let's do this let's do this one more time. 54 00:04:10,060 --> 00:04:15,700 If I have the call the wrong way and if I also have my data the wrong way. 55 00:04:16,180 --> 00:04:20,120 But I still say make directory numbers too. 56 00:04:20,470 --> 00:04:23,120 So this will ignore the calendar and the date. 57 00:04:23,290 --> 00:04:30,550 Or actually it will show you like a command not found message but it will still execute the numbers 58 00:04:30,550 --> 00:04:33,840 too or it will actually create the numbers to the rectory. 59 00:04:33,880 --> 00:04:41,530 So as you can see here Kommandos fan for the calendar command not found for the date but I still have 60 00:04:41,530 --> 00:04:43,100 numbers to created. 61 00:04:43,510 --> 00:04:44,130 Awesome. 62 00:04:44,230 --> 00:04:45,990 So let's do one more example. 63 00:04:45,990 --> 00:04:55,300 When using the semi-colon method I will create a file called Touch or three text with my touch command 64 00:04:55,870 --> 00:05:06,220 and I will move this text file to my non-bird and then I will show the date on the calendar and then 65 00:05:06,280 --> 00:05:07,000 owl. 66 00:05:07,420 --> 00:05:09,570 And that that's it that's it. 67 00:05:10,070 --> 00:05:19,060 OK so here I'll create a file called text on my desktop but this file will not appear on my desktop 68 00:05:19,060 --> 00:05:25,000 because once I created it I will move it right away to my numbers directory and then I will show the 69 00:05:25,000 --> 00:05:26,580 date on the terminal. 70 00:05:26,680 --> 00:05:32,790 And also I will show the calendar so that excuses as you can see I have the date and the calendar year 71 00:05:32,820 --> 00:05:33,560 shown. 72 00:05:33,790 --> 00:05:39,530 And if I open my numbers directly now I can see my text file moved into my number to record. 73 00:05:39,660 --> 00:05:45,760 So this is kind of complex right because I created a text file and as long as I created it I already 74 00:05:45,760 --> 00:05:48,270 moved it to number two numbers directory. 75 00:05:48,290 --> 00:05:55,000 So that's why you don't see the text files here because once I created it I moved it right away to my 76 00:05:55,000 --> 00:05:55,910 number directory. 77 00:05:55,930 --> 00:06:02,720 So as you can see you can you can have a lot of fun when combined multiple commands at the same time. 78 00:06:03,080 --> 00:06:03,740 OK. 79 00:06:03,820 --> 00:06:05,320 I just want you to guys. 80 00:06:05,320 --> 00:06:12,100 One more thing before discussing the second Messud if you have an exit command you know that exit will 81 00:06:12,100 --> 00:06:14,270 exit on our terminal right. 82 00:06:14,770 --> 00:06:23,950 So if you have an exit when you're combining multiple commands it will basically ignore everything after 83 00:06:23,950 --> 00:06:24,130 it. 84 00:06:24,130 --> 00:06:25,650 So what do I mean business. 85 00:06:25,660 --> 00:06:31,510 So if I if you have make directory number three and then you have exit and then you have make directory 86 00:06:32,610 --> 00:06:34,050 numbers. 87 00:06:34,250 --> 00:06:36,710 Here I have to just say number three. 88 00:06:37,060 --> 00:06:38,930 And then here number four. 89 00:06:39,310 --> 00:06:40,470 Number four. 90 00:06:40,480 --> 00:06:43,790 And then here I have a date and have code. 91 00:06:43,990 --> 00:06:47,920 So here I am creating a directory which is number three. 92 00:06:48,370 --> 00:06:54,940 But however I am exiting the terminal and then I am creating a number for the Rectory and I'm showing 93 00:06:54,940 --> 00:06:56,220 the date on the calendar. 94 00:06:56,230 --> 00:07:04,700 So logically what will happen here is that here I will this will this will execute successfully right. 95 00:07:04,900 --> 00:07:11,980 So I will be able to create my numbers three directory however once I exit my terminal there is no way 96 00:07:11,980 --> 00:07:15,930 that I'm able to create numbers for show the date or the calendar. 97 00:07:16,060 --> 00:07:19,860 So all these commands after the exit command will be just ignored. 98 00:07:19,920 --> 00:07:27,610 So less excuses as you can see only numbers 3 was created and numbers fourth. 99 00:07:27,670 --> 00:07:30,490 Number four was not created. 100 00:07:30,650 --> 00:07:36,610 And of course you cannot see the date or the calendar when the terminal is closed. 101 00:07:37,220 --> 00:07:39,170 OK. 102 00:07:39,170 --> 00:07:41,010 So this was the first message. 103 00:07:41,060 --> 00:07:47,670 So let's now delete everything here that we just created and we discussed the second method now. 104 00:07:47,690 --> 00:07:52,660 So the second method is very similar but it has just multiple differences. 105 00:07:53,150 --> 00:08:01,160 So you can still combine multiple commands using the second method which is the ampersand method or 106 00:08:01,160 --> 00:08:03,160 the double ampersand method. 107 00:08:03,230 --> 00:08:05,890 So let's go to my desktop here. 108 00:08:06,540 --> 00:08:15,060 And so if you want to execute multiple commands at once You can also use the double ampersand. 109 00:08:15,080 --> 00:08:21,830 So this is the general format here would be your first command and then double ampersand second command 110 00:08:22,460 --> 00:08:26,700 double ampersand blah blah blah all the way until your and command. 111 00:08:27,440 --> 00:08:27,840 OK. 112 00:08:27,890 --> 00:08:30,880 So as you can see the format is very similar. 113 00:08:31,340 --> 00:08:39,730 But here the difference is you just substitute a semi colon with an ampersand as you can see this is 114 00:08:39,830 --> 00:08:41,020 the difference here. 115 00:08:41,360 --> 00:08:43,980 OK so let's try this. 116 00:08:44,180 --> 00:08:50,640 And also the order matters as with just like the same case where when we have a semicolon. 117 00:08:50,720 --> 00:08:59,330 So here I'll just type date Cal I have my date shown and then the calendar and you can see and the order 118 00:08:59,330 --> 00:09:05,730 matters so if I type Cal date it will show me the calendar first and then the date. 119 00:09:05,900 --> 00:09:07,480 So the same thing. 120 00:09:07,760 --> 00:09:09,910 Just like using the semicolon method. 121 00:09:10,340 --> 00:09:13,150 But there is one fundamental difference that I want to get. 122 00:09:13,160 --> 00:09:14,950 I wanted to discuss with you guys. 123 00:09:16,010 --> 00:09:16,580 OK. 124 00:09:16,840 --> 00:09:18,670 So let's make a directory number. 125 00:09:20,180 --> 00:09:23,350 And then date and then calendar. 126 00:09:23,370 --> 00:09:23,870 Right. 127 00:09:24,060 --> 00:09:30,980 So this will just do the normal thing it will create numbers it will show you the date and show you 128 00:09:31,000 --> 00:09:32,740 the number or calendar. 129 00:09:32,740 --> 00:09:37,030 However I want you guys to know one fundamental difference. 130 00:09:37,690 --> 00:09:44,350 So unlike unlike the semi colon method where it will only select the correct commands and ignore all 131 00:09:44,350 --> 00:09:46,610 the other ones here. 132 00:09:47,060 --> 00:09:52,210 It uses what we call a short circuit evaluation. 133 00:09:52,240 --> 00:09:59,920 You probably hear heard this term if you are familiar with computer science or with programming languages 134 00:10:00,660 --> 00:10:03,740 there is something called a short circuit evaluation. 135 00:10:03,940 --> 00:10:12,290 So basically what is this what this means is the double ampersand method will execute just like normal 136 00:10:12,500 --> 00:10:15,810 until it encounters an error. 137 00:10:15,980 --> 00:10:20,900 And after this error it will just ignore all the other commands that comes after it. 138 00:10:20,930 --> 00:10:23,360 So what do I mean by this. 139 00:10:23,420 --> 00:10:31,250 So if you Thaiday to the wrong way and then you type Callander the right way and you want to make a 140 00:10:31,250 --> 00:10:34,280 directory in numbers to. 141 00:10:34,280 --> 00:10:39,650 So if I execute this command here if I was using the same I call a method. 142 00:10:39,920 --> 00:10:43,580 It will only select the good commands or the correct command. 143 00:10:43,580 --> 00:10:50,800 So if I was using the semicolon method the calendar will be shown and numbers 2 will be created. 144 00:10:50,800 --> 00:10:56,870 However because you are using the double ampersand here and we have an error in the same in the first 145 00:10:56,870 --> 00:11:02,720 command this will lead that all the other commands will not execute. 146 00:11:03,650 --> 00:11:06,320 As you can see it with it it will tell you. 147 00:11:06,320 --> 00:11:07,750 Command not found. 148 00:11:07,880 --> 00:11:12,050 And the calendar is not shown and numbers 2 are not created. 149 00:11:12,050 --> 00:11:15,910 So this is what we call a short circuit evaluation. 150 00:11:16,040 --> 00:11:22,990 So once we have an error all the other guys coming after this error will not be execute. 151 00:11:24,340 --> 00:11:34,620 So this will be different for example if we do something like that they'd make directory non-birds too. 152 00:11:34,970 --> 00:11:37,900 So here the error is in the second command. 153 00:11:37,980 --> 00:11:43,230 So the calendar will be able to show that the calendar will be executed correctly. 154 00:11:43,230 --> 00:11:48,470 However the date is it is it is a typo here. 155 00:11:48,570 --> 00:11:53,250 So this will lead that number to will not be created. 156 00:11:53,400 --> 00:12:01,590 And for example if your philosophy excuses to Adkins's the calendar is shown but the date is not correct 157 00:12:01,610 --> 00:12:06,460 I think and see so that this will leave that number two will not be created. 158 00:12:06,510 --> 00:12:08,740 However if you do it the other way around. 159 00:12:08,740 --> 00:12:12,420 So if you change the ordering so of course 160 00:12:19,480 --> 00:12:24,180 this will be different so numbers will be created because it is the first command here. 161 00:12:24,220 --> 00:12:31,270 However because calendar is not correct this will not be able to show the date OK. 162 00:12:31,630 --> 00:12:38,160 As you can see number sooths created Kelle is not found and the date is not shown as a result of this. 163 00:12:38,350 --> 00:12:42,740 So this is what we call a short circuit evaluation. 164 00:12:42,790 --> 00:12:44,700 OK so that's it for this video. 165 00:12:44,790 --> 00:12:51,060 And as you guys learn now we can combine multiple commands at the same time. 166 00:12:51,550 --> 00:12:53,790 And we use we have two methods. 167 00:12:53,900 --> 00:13:07,940 The semicolon master and the double ampersand Messud two I hope you guys enjoyed it. 168 00:13:07,950 --> 00:13:12,820 And I actually actually like executing multiple commands at the same time. 169 00:13:12,900 --> 00:13:19,180 It's makes it makes you more efficient when using the Linux command line. 170 00:13:19,560 --> 00:13:20,160 Ciao.