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.

Run Multiple Linux Commands in One Single Command

Run Multiple Linux Commands in One Single Command

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.

1) Use ;

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

2) Use &&

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

3) Use ||

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.

Share this:

ITSmarttricks Team

This is Mangesh Dhulap the Founder and Editor of IT SMART TRICKS have 6+ years of Industrial Experience. We expect from our visitors to like, share, and comment on our posts.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.