How to run multiple linux commands at the same time or run multiple linux commands in one line. Running multiple commands on the same Linux line is easy, check out how to do it:
How to run multiple Linux commands on one line
On Linux, there are 3 ways to run multiple commands on the same line:
- ; Team 1 ; Command 2 – will run command 1 first and then command 2.
- && Command 1 && Command 2 – this will be command 2 only if command 1 succeeds
- || Team 1 || Command 2 – This will be command 2 only if command 1 fails.
Below are the usage details:
- Using ;
When you use ; whether the first command (command 1) succeeds or not, always run the second command (command 2).
- Using &&
When you use &&, the second command (command 2) will only be executed after the first command (command 1) succeeds.
- Using ||
When you use || the only one when the second command (command 2) will be executed only when the first command (command 1) is not executed.
Running more than 2 commands at the same time on the same line
You can use ; to run multiple Linux commands on one line. Just use a semicolon (;) to add/combine multiple commands on the same line. You can use the following format:
command 1; command 2; command 3
NOTE. Command 1 will run first, then command 2 will run, and then command 3 will run. The commands will run regardless of whether the previous command was successful or not.
Similarly, you can use command 1 && command 2 && command 3.