How to run multiple commands at once in CMD

Command Prompt is useful software for you to perform special tasks in Windows. During use, there will be times when you need to run many commands simultaneously. 

Run multiple commands at once using a .Bat . file

Usually, there will be situations where you need to run multiple commands like the following:

  1. Run multiple commands at the same time
  2. Run multiple commands one at a time
  3. Run subsequent commands only if the first command was executed successfully
  4. Run subsequent commands only if the first file fails to execute

With the method of running commands using a .Bat file, we will solve the case of 'running multiple commands at the same time'. For the next cases, please scroll down to the bottom of the article.

Step 1: Use the search box to find and open the Notepad application.

Picture 1 of How to run multiple commands at once in CMD

Step 2: Enter all the commands in the Notepad file that you want to execute at once. For this task, I want to clear the DNS cache, then refresh it. Normally would have to enter 4 commands in CMD, but now I add all commands in one file.

Commands include:

  1. ipconfig /displaydns
  2. ipconfig /flushdns
  3. ipconfig /release
  4. ipconfig /renew

Picture 2 of How to run multiple commands at once in CMD

Step 3: Press Ctrl + S to proceed to save the file. In the save window, choose an easy-to-remember name for the file and set the extension .bat.

Click Save when ready.

Picture 3 of How to run multiple commands at once in CMD

Step 4: Now go to the location where you saved the file, double click on it to launch it.

Picture 4 of How to run multiple commands at once in CMD

The commands will automatically be run in CMD and all you have to do is wait for the results.

Picture 5 of How to run multiple commands at once in CMD

Run multiple commands using &, &&, || . symbols

This way, you will run many commands in CMD with the remaining 3 cases mentioned above:

  1. Run multiple commands one at a time
  2. Run subsequent commands only if the first command was executed successfully
  3. Run subsequent commands only if the first file fails to execute

Symbol &

The first way is to use '&' in between the commands that you want to run. This will allow commands to be run sequentially.

Example: ipconfig /displaydns & ipconfig /flushdns & ipconfig /release & ipconfig /renew

Picture 6 of How to run multiple commands at once in CMD

Symbol &&

In this case, you add '&&' in between the commands: the second command runs only as long as the first one succeeds.

Example: ipconfig /displaydns && ipconfig /flushdns && ipconfig /release && ipconfig /renew

Picture 7 of How to run multiple commands at once in CMD

Symbol ||

The last method is easy to understand, you just need to add || in between commands, the 2nd command runs only when the first command executes failed.

Example: ipconfig /displaydns || ipconfig /flushdns || ipconfig /release || ipconfig /renew

Picture 8 of How to run multiple commands at once in CMD

Since the first command executed successfully, the chain of commands stopped right there. Alternatively, you can also combine symbols in the same command line: command1 & command2 && command3 || command4.

Conclusion

Very interesting isn't it? Hopefully these simple tricks will save you time in the process of running commands on CMD. Good luck!

Update 21 July 2021
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile