Run Multiple Linux Commands in One Single Command
In this article, we are going to learn How to Run Multiple Linux Commands in One Single Command. On the off chance that you use Linux day by day, you will realize that the command line is the most powerful tool when you working with files, configuring system software programming, and running them. It turns out to be significantly more productive in the event that you run at least two command without a moment’s delay on the command line and save a decent arrangement of time.
There are 3 ways to run multiple Linux commands in One Single Command:
||cmd1; cmd2||The “;” operator runs all commands regardless of whether the earlier ones are failed or not.|
||cmd1 && cmd2||The “&&” operator carries out the second command only if the preceding command executes successfully.|
||cmd1 || cmd2||The “||” operator executes the second command only if the precedent command returns an error.|
Let me explain to you in more detail how you can execute multiple commands in Linux in one go.
No matter the first command cmd1 run successfully or not, always run the second command cmd2:
# cmd1; cmd2 $ cd myfolder; ls # no matter cd to myfolder successfully, run ls
Only when the first command cmd1 run successfully, run the second command cmd2:
# cmd1 && cmd2 $ cd myfolder && ls # run ls only after cd to myfolder
Only when the first command cmd1 failed to run, run the second command cmd2:
# cmd1 || cmd2 $ cd myfolder || ls # if failed cd to myfolder, `ls` will run
That’s all, In this article, we have explained Run Multiple Linux Commands in One Single Command. If you like this article, then just share it and then do subscribe to email alerts for Linux, Windows, macOS, Android, Internet, Firewall and Security, CCTV tutorials. If you have any questions or doubts about this article, please comment.