How to run multiple commands at once in CMD

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.

How to run multiple commands at once in CMD Picture 1

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

How to run multiple commands at once in CMD Picture 2

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.

How to run multiple commands at once in CMD Picture 3

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

How to run multiple commands at once in CMD Picture 4

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

How to run multiple commands at once in CMD Picture 5

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

How to run multiple commands at once in CMD Picture 6

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

How to run multiple commands at once in CMD Picture 7

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

How to run multiple commands at once in CMD Picture 8

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!

4 ★ | 147 Vote

May be interested

  • 15 Tar commands should try in Linux15 Tar commands should try in Linux
    on * nix operating systems, such as linux, the commonly used utility is tar. the name of this command comes from archive tape, because it was originally designed to back up data on tape.
  • How to Run Linux Commands on Windows with WSL 2How to Run Linux Commands on Windows with WSL 2
    windows subsystem for linux 2 builds on the success of the original wsl, and the newer wsl 2 brings more power and reliability to users. it is important that you understand how to use linux commands and utilities on windows subsystem for linux 2.
  • Combine all the most basic AutoCAD commandsCombine all the most basic AutoCAD commands
    using autocad shortcut commands helps to manipulate faster. if you do not know all the cad commands, please see the summary of autocad commands that we have done below.
  • Top 10 examples of Netstat commands on LinuxTop 10 examples of Netstat commands on Linux
    netstat is a command line utility that can be used to list all network connections (sockets), allowing comparison with network connections, routing tables, interface records, connection spoofing.
  • What is CMD Commands in WindowsWhat is CMD Commands in Windows
    what is cmd commands in windows. for those who are new to computers, they will not know what cmd is and how to use it. so in the following article of tipsmake.com will help you answer what is cmd? and the most common commands used in cm
  • Use commands and some tips for Mac OS XUse commands and some tips for Mac OS X
    in this tutorial we will show you how to use some commands and tips for mac os x.
  • 10 Netsh commands of Windows Server 2008 should know10 Netsh commands of Windows Server 2008 should know
    introducing 10 netsh commands that every administrator should know. netsh is very powerful and flexible, however, because it is not possible to select netsh 'most important' commands, since the importance of each command depends on administrative tasks in each specific task. so what we introduced in this article is 10 commands that we feel are valuable for you and help you when you encounter problems.
  • 10 commands to master when working with Cisco IOS10 commands to master when working with Cisco IOS
    if you want to master the cisco ios, you need to learn some necessary commands. the following article will summarize 10 useful commands to handle various troubleshooting and configuration tasks.
  • PHP syntaxPHP syntax
    before starting programming in any language, the basic syntax and program structure is very important. this chapter introduces you to the basic php syntax, including: php tags, comments, print commands, echo commands, and two print and echo commands.
  • Review changes in GitReview changes in Git
    after rechecking the deposit details, jerry realizes that the string length cannot be negative, so he decides to change the type of my_strlen function.