Copyright

Batch File Commands: Pause, Delete, Sleep & More

Instructor: Alan Goodbrand

Alan has been an adult educator for over 20 years and has a Master's Degree in Software Engineering.

Windows allows you to create batch files of commands that can be executed as a whole. This lesson introduces you to some of the more basic commands, such as SLEEP, PAUSE and DEL, as well as some other useful ones.

Batch File Commands: Pause, Delete, Sleep & More

Windows batch files can be created with any basic text editor, but the most common one is Notepad. They should be saved as ASCI files and should have the extension of .cmd. You can execute a batch file simply by double clicking on it.

REM Command

The most basic command is the REM command. REM stands for REMark, and anything can be put in this command. It is simply a way of documenting your command file. For example, you might write:

REM *** This file was written by David on June 4, 2015 ***

Go ahead and open Notepad and create a new file. Write a REMark command on the first line and add any descriptive text you want. Click Save or Save As. Save the file to any directory you wish (for example 'My Documents' which should already exist) and give it any name you wish (for example 'MyFirstBatchFile'), but give it the extension .cmd. Make certain that at the bottom of the save window, where it says 'encoding', the encoding type says 'ASCI'. If it doesn't say 'ASCI', use the dropdown arrow to select 'ASCI' from the options.

Once you've saved the file, exit Notepad and use File Explorer to open the folder where you saved the batch file. Double click on your batch file. What happened?! The screen should've flashed with what looked like a black screen and then gone back to normal. What happened was that the command screen opened and your file was executed in batch mode. When the execution of your file finished, the command screen closed. But it all happened so fast that you couldn't see anything.

PAUSE Command

Let's change things a bit so we can see what's happening. Open your .cmd batch file in Notepad. On line 2, immediately beneath the REM command, enter the command PAUSE. Your file should now look something like this:

REM *** This file was written by David on June 4, 2015 ***
PAUSE

Save the batch file, switch to Explorer, and double click your batch file again. This time the black command screen stays put. That's because the PAUSE command says to Windows, 'Stop execution of the batch file and wait for the user to press any key'.

SLEEP Command

The SLEEP command functions much like the PAUSE command, except instead of waiting for the user to press 'any key', the SLEEP command requires a parameter to tell it how many seconds to sleep. Switch back to your batch file in Notepad and on line 3 enter the command SLEEP 10. Your file should now look like this:

REM *** This file was written by David on June 4, 2015 ***
PAUSE
SLEEP 10

Save it and switch back to Explorer and double click on the batch file. This time Windows will execute all commands in order up to the SLEEP command, and then the screen will pause for 10 seconds before continuing.

TIMEOUT Command

In some versions of Windows, the SLEEP command has been replaced with the TIMEOUT Command. If you found that when you double clicked the batch file, it did not sleep or produced an error message, switch back to Notepad and replace SLEEP with TIMEOUT, save the file and double click it again in Explorer. If the SLEEP command didn't work and you had to use the TIMEOUT command, your batch file should now look like this:

REM *** This file was written by David on June 4, 2015 ***
PAUSE
TIMEOUT 10

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support