Windows OS

How to Sleep for Five Seconds in CMD?

The “sleep” command is used to add delay in some processes but unfortunately sleep or delay commands do not support windows operating systems. In the Windows operating system, we can utilize the “timeout” command that can delay the execution of commands for some seconds or for a specified time. The sleep process is carried out to complete the ongoing process or the command’s execution before moving toward the next process.

We will demonstrate the way to sleep for five seconds in CMD in this post.

How to Sleep for Five Seconds in CMD?

Sometimes the user wants to pause or delay the execution of some commands or scripts for a specified time. For a better understanding, we have performed the following steps to sleep for five seconds in CMD:

Step 1: Open Command Prompt

Press the “CTRL+R” key to launch the Run box, type “cmd” in the “Open” drop-down menu, and press the “OK” button to Open Command Prompt:

Step 2: Sleep for Five Seconds

To put Command Prompt to sleep for five seconds, use the “timeout” command. After 5 seconds, the next instruction can be executed:

> timeout /t 5

 

The Command prompt successfully allowed us to sleep for five seconds.

Bonus-Tip: How to Sleep for Five Seconds in CMD Using Batch Script?

Batch Script is a simple text file that contains several commands. When running a batch script, each command is run in sequence and one at a time. Here, we have demonstrated the method to wait for five seconds in the execution of a batch file.

Step 1: Create a Simple Batch File

Do right-click anywhere (where you want to create a batch file), move the pointer on the “New” option then select “Text Document” from the displayed options:

We have used the following code inside the batch file. Once you have written the code, press the “CTRL+SHIFT+S” key to save the file:

@echo Hello
@echo First cmd sleep Time...
timeout /t 5
@echo We are done...
pause

 

You can see that we have executed four commands. After the second command, we have added a delay for 5 seconds.

Pressing “CTRL+SHIFT+S” will bring up the “Save As” window. Name the file “Script.bat” and save it. Remember to change the “.txt” extension to “.bat“.

Step 2: Execute Batch Script

You can see that we have successfully created a batch script. Next, double-click on the batch script to execute it. By default, it will execute in Command Prompt:

You can see that the batch script is executing in Command Prompt. After running two commands, the “timeout” command will execute for 5 seconds. If you do not want to wait for five seconds, you can press any key to interrupt it:

When the five seconds are completed, the final command is successfully carried out:

If we add the “nobreak” option in the “timeout” command, then you cannot interrupt the waiting time. We have practiced the above batch file with the “/nobreak” option:

Here, you can see that we are unable to interrupt 5 second delay of the timeout command:

Five seconds of delay have been successfully applied to the batch script during command execution. The “pause” is used to suspend batch program processing:

That’s it! We have used the CMD to sleep for five seconds in windows.

Conclusion

To Sleep for five seconds in Command Prompt, we can utilize the “timeout” command. The timeout is mainly used to sleep some process or command execution for some time or a specified time. To use the “timeout” command to sleep for five seconds, execute the “timeout /t 5” command in Command Prompt. In this post, we have applied the “timeout /t 5” command in multiple scenarios to wait for five seconds in CMD.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.