How to run multiple commands in linux terminal using special characters | Pro Tech guides

How to run multiple commands in linux terminal using special characters

In linux you can run two or more commands using some special characters like &&, ; and ||. It is very useful in bash scripting and saves time.

How to run multiple linux commands in a single terminal

run multiple command in linux
Run multiple commands using special characters

Hello, guys Today I'm going to show you how to run two or more terminal commands at once in Linux.

Till now you have seen how you can use commands. But you haven't seen how to combine two commands and run them together.

So there are few options you can use to combine commands,

Method 1 (using semicolon)

combine two commands 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.

This is going to combine these commands and then it is going to show us the output.

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 command using &&
Combine using &&

$command1 && command2 && command3
The second command to combine a few commands together is using this ampersand symbol (&&).

For example, I want to do "cd / && ls && cd" and press ENTER.

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 Broken Vertical Bar ||
Combine using ( || )

$command1 || command2 || command3
The next is the "OR" option. So you can use these vertical bar (||).

For example, you use the "cd / || ls" press ENTER.

The output is the combination of logical OR.

So if the first command is successful it's not going to the second command.

combine using ||
Example

Once the first command is not successful it's going to execute the next command so it's like a logical "OR" operation.


Conclusion

So these are the few options you can use to combine command in Linux.

I hope you have enjoyed this tutorial.

HAVE A NICE DAY💗

See also,
Name

Apps,3,Games,1,Linux,38,Linux Commands,37,Network-Devices,1,Networking,1,Terminal Apps,2,Termux,17,Userland,3,Windows,1,
ltr
item
Pro Tech guides: How to run multiple commands in linux terminal using special characters
How to run multiple commands in linux terminal using special characters
In linux you can run two or more commands using some special characters like &&, ; and ||. It is very useful in bash scripting and saves time.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5__Vo_YKSkVDwdiVzi4bWt_J8VBJie7LvbbSEnO5o4SmFQphFXMqpSshzyJFn1EZyhyphenhyphenqh8WnzIKAg2_ohLIm4DUbMbuoP9_AbYP1S4qdm5HkaqlA5DeLIo_zyL3oJMO4Pv6PJIEbgWC8/s16000/run-multiple-commands-in-linux.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5__Vo_YKSkVDwdiVzi4bWt_J8VBJie7LvbbSEnO5o4SmFQphFXMqpSshzyJFn1EZyhyphenhyphenqh8WnzIKAg2_ohLIm4DUbMbuoP9_AbYP1S4qdm5HkaqlA5DeLIo_zyL3oJMO4Pv6PJIEbgWC8/s72-c/run-multiple-commands-in-linux.png
Pro Tech guides
https://devops-digest.blogspot.com/2021/04/how-to-run-multiple-commands-in-linux.html
https://devops-digest.blogspot.com/
https://devops-digest.blogspot.com/
https://devops-digest.blogspot.com/2021/04/how-to-run-multiple-commands-in-linux.html
true
7053638852026728047
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content