How to run multiple linux commands in a single terminal
![]() |
Run multiple commands using special characters |
Method 1 (using semicolon)
![]() |
Combine using a semicolon (;) |
$command1 ; command2
The first option which you can use to combine command is a semicolon (;) For example, I want to use the "cd" command and also I want to list all the directory. So I am going to use the "ls" command and in between, I have used this semicolon and press ENTER.
First, it has printed the output for the "cd" command and then it has executed the "ls" command. So in this way you can combine these commands using a semicolon (;).
Note:
whenever you use semicolon If you enter the wrong command (or) misspelled. It will show the error in the particular command and jump to next command.
It doesn't stop executing command if one command fails.
Method 2 (using &&)
![]() |
Combine using && |
$command1 && command2 && command3
So it gives the same output first "cd /" next "ls" and last "cd". But what is the difference between semicolon (;) and ampersand (&&)?
- whenever you use this semicolon (;) it's going to run every command regardless of the success or failure of the previous command.
- But in ampersand (&&), If the previous command fails. It stops the execution.
Method 3 (using || )
![]() |
Combine using ( || ) |
$command1 || command2 || command3
![]() |
Example |
Once the first command is not successful it's going to execute the next command so it's like a logical "OR" operation.