Hello everyone in this is with you I'll show you how to execute multiple Linux commands in a single
line and I will show you how to accomplish this using two different methods.
So let's get started.
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
me the date as you know from before and if I type the call command and execute it it will show me the
calendar.
So so far we have been executing our commands one at a time as you can see.
So here I am securing my commands one at a time.
However you can execute multiple commands at the same time.
So how can we do this.
So here we are going to explain the first method which is called the semi call mastered.
So in general you can execute your first command and then you separated by a semicolon here your second
command semi colon and then cetera blah blah blah.
It will be your answer command.
Oh this is the general format if you want to execute multiple commands.
In this case we have any commands.
At the same time using the semicolon mentioned So let's so let's examine this.
So if I type a date in my colon calender
as you can see this will show me the date and the calendar.
All at once.
So the colon is basically the same thing with using programming languages.
So if you know C++ you would know that after lie after you're done with your statement you have to put
a semi-colon.
Basically it's called Like a statement separator so in C++ you can say something like this.
You can say interger x is equal to three and then semi-colon.
And to your Y is equal to for my colon.
So this is valid in C++ and the same thing applies here.
You can have multiple statements on the same line in C++ and also you can have multiple command on the
same line in Linux.
OK Arsen So let's get a more advanced here.
So if I type make directory numbers then date and then calendar.
This will first make a directory called numbers and then it'll show me the date and then it will show
me the calendar.
And you have to know that the ordering matters to you.
So first I have my other my numbers directory then it shows me the data then it shows me the calendar.
OK.
And the order matters so if you say date to my colon calendar this will show you that the date first
and then the calendar.
However if you say calendar say my column date it will show you the calendar first and then it will
show you the date.
So here the order matters.
OK you also have to know one thing when using the semicolon method the semi-colon method ignores all
incorrect commands or it actually ignores all typos and errors.
So what do I mean by that.
So if you say call an uppercase C L you know that this this one is non-valid right.
Command not found.
Because our Linux commands are case sensitive.
However if you say that then semi-colon date it will still show you the date so it will tell you.
Command not found for calendar but I will still show you the date.
So as you can see using a semi colon it actually ignores all the arrows.
Right.
It will only only show you or it will only execute the correct command.
So let's do this let's do this one more time.
If I have the call the wrong way and if I also have my data the wrong way.
But I still say make directory numbers too.
So this will ignore the calendar and the date.
Or actually it will show you like a command not found message but it will still execute the numbers
too or it will actually create the numbers to the rectory.
So as you can see here Kommandos fan for the calendar command not found for the date but I still have
numbers to created.
Awesome.
So let's do one more example.
When using the semi-colon method I will create a file called Touch or three text with my touch command
and I will move this text file to my non-bird and then I will show the date on the calendar and then
owl.
And that that's it that's it.
OK so here I'll create a file called text on my desktop but this file will not appear on my desktop
because once I created it I will move it right away to my numbers directory and then I will show the
date on the terminal.
And also I will show the calendar so that excuses as you can see I have the date and the calendar year
shown.
And if I open my numbers directly now I can see my text file moved into my number to record.
So this is kind of complex right because I created a text file and as long as I created it I already
moved it to number two numbers directory.
So that's why you don't see the text files here because once I created it I moved it right away to my
number directory.
So as you can see you can you can have a lot of fun when combined multiple commands at the same time.
OK.
I just want you to guys.
One more thing before discussing the second Messud if you have an exit command you know that exit will
exit on our terminal right.
So if you have an exit when you're combining multiple commands it will basically ignore everything after
it.
So what do I mean business.
So if I if you have make directory number three and then you have exit and then you have make directory
numbers.
Here I have to just say number three.
And then here number four.
Number four.
And then here I have a date and have code.
So here I am creating a directory which is number three.
But however I am exiting the terminal and then I am creating a number for the Rectory and I'm showing
the date on the calendar.
So logically what will happen here is that here I will this will this will execute successfully right.
So I will be able to create my numbers three directory however once I exit my terminal there is no way
that I'm able to create numbers for show the date or the calendar.
So all these commands after the exit command will be just ignored.
So less excuses as you can see only numbers 3 was created and numbers fourth.
Number four was not created.
And of course you cannot see the date or the calendar when the terminal is closed.
OK.
So this was the first message.
So let's now delete everything here that we just created and we discussed the second method now.
So the second method is very similar but it has just multiple differences.
So you can still combine multiple commands using the second method which is the ampersand method or
the double ampersand method.
So let's go to my desktop here.
And so if you want to execute multiple commands at once You can also use the double ampersand.
So this is the general format here would be your first command and then double ampersand second command
double ampersand blah blah blah all the way until your and command.
OK.
So as you can see the format is very similar.
But here the difference is you just substitute a semi colon with an ampersand as you can see this is
the difference here.
OK so let's try this.
And also the order matters as with just like the same case where when we have a semicolon.
So here I'll just type date Cal I have my date shown and then the calendar and you can see and the order
matters so if I type Cal date it will show me the calendar first and then the date.
So the same thing.
Just like using the semicolon method.
But there is one fundamental difference that I want to get.
I wanted to discuss with you guys.
OK.
So let's make a directory number.
And then date and then calendar.
Right.
So this will just do the normal thing it will create numbers it will show you the date and show you
the number or calendar.
However I want you guys to know one fundamental difference.
So unlike unlike the semi colon method where it will only select the correct commands and ignore all
the other ones here.
It uses what we call a short circuit evaluation.
You probably hear heard this term if you are familiar with computer science or with programming languages
there is something called a short circuit evaluation.
So basically what is this what this means is the double ampersand method will execute just like normal
until it encounters an error.
And after this error it will just ignore all the other commands that comes after it.
So what do I mean by this.
So if you Thaiday to the wrong way and then you type Callander the right way and you want to make a
directory in numbers to.
So if I execute this command here if I was using the same I call a method.
It will only select the good commands or the correct command.
So if I was using the semicolon method the calendar will be shown and numbers 2 will be created.
However because you are using the double ampersand here and we have an error in the same in the first
command this will lead that all the other commands will not execute.
As you can see it with it it will tell you.
Command not found.
And the calendar is not shown and numbers 2 are not created.
So this is what we call a short circuit evaluation.
So once we have an error all the other guys coming after this error will not be execute.
So this will be different for example if we do something like that they'd make directory non-birds too.
So here the error is in the second command.
So the calendar will be able to show that the calendar will be executed correctly.
However the date is it is it is a typo here.
So this will lead that number to will not be created.
And for example if your philosophy excuses to Adkins's the calendar is shown but the date is not correct
I think and see so that this will leave that number two will not be created.
However if you do it the other way around.
So if you change the ordering so of course
this will be different so numbers will be created because it is the first command here.
However because calendar is not correct this will not be able to show the date OK.
As you can see number sooths created Kelle is not found and the date is not shown as a result of this.
So this is what we call a short circuit evaluation.
OK so that's it for this video.
And as you guys learn now we can combine multiple commands at the same time.
And we use we have two methods.
The semicolon master and the double ampersand Messud two I hope you guys enjoyed it.
And I actually actually like executing multiple commands at the same time.
It's makes it makes you more efficient when using the Linux command line.
Ciao.