Chapter 1: Meet the Command Prompt
Version: Windows 10 / 11 · cmd.exe
Another Way to Talk to Your Computer
Most of the time, you talk to your computer by pointing and clicking. You double-click an icon to open a program. You drag a file to move it. That works well, and you will keep doing it.
There is a second way to talk to your computer: by typing words.
You type a short instruction, press Enter, and the computer does exactly that job and writes back an answer. No hunting through menus. No guessing which button does what. The instruction is right there in plain text, and the answer is plain text too.
The program that takes those typed instructions is called the Command Prompt, and the program behind the window is cmd.exe . People usually shorten its name to cmd.
This whole book is about cmd: first typing commands yourself, then writing them into files so cmd can run a whole list of them for you. That second part is where the real time saving starts.
What cmd Is, and What It Is For
cmd is a small program that ships with Windows. It has been part of Windows for a very long time, and it is already on your computer. There is nothing to install.
When you open it, you get a plain window, usually black, with a short line of text and a blinking cursor. That plain look hides what it can do:
- It can show you information about your computer and your files.
- It can create, copy, rename, and delete files and folders.
- It can run other programs.
- It can repeat the same job many times without getting bored or sloppy.
Why type, when clicking exists? Three honest reasons.
Typing is exact. A menu can move between versions. A window can look different on your friend's computer. A command you type is the same command every time, letter for letter.
Typing is fast for repeat jobs. If a job takes nine clicks and you do it every day, that is a lot of clicks in a month. One typed line can replace all of them.
Typing can be saved. This is the big one. A command you type can be written into a file, and that file can be run again tomorrow, next week, or a hundred times in a row. Clicks cannot be saved like that.
Opening the Command Prompt
There are several ways in. Learn all three, because each one is the fastest in a different situation.
Way 1: The Start Menu
- Click the Start button, or press the Windows key on your keyboard.
- Type Command Prompt .
- Click Command Prompt in the results, or press Enter.
This is the way to use when you just want a cmd window and you do not care which folder it starts in.
Way 2: Win+R
- Hold the Windows key and press R. A small Run box opens.
- Type cmd in the box.
- Press Enter.
This is the fastest way once your fingers know it. Two keys, three letters, Enter, done.
Way 3: From a Folder
- Open any folder in File Explorer.
- Click once in the address bar at the top of the folder window, where the folder path is shown.
- Type cmd and press Enter.
A cmd window opens, and here is the trick: it starts in that folder. If you were looking at your Downloads folder, cmd opens already standing in Downloads. Later, when your scripts live in one folder, this trick saves you a lot of travelling.
PRO TIP Way 3 is the one most people never learn, and it is the one you will use most while working through this book. Whenever a chapter says "open cmd in your practice folder", this is how.
The Prompt: cmd Telling You Where It Stands
When cmd opens, it prints a short line and waits. That line is called the prompt. On many computers it looks like this:
C:\Users\You> The prompt is not decoration. It is cmd telling you where it is standing right now, before you have typed anything.
The three parts of the prompt: the drive, the folder cmd is working in, and the ready sign.
The parts, one at a time:
- C: is the drive — the disk cmd is looking at. Most Windows computers start on drive C.
- \Users\You is the folder cmd is standing in. The backslashes separate the folders inside folders: inside Users , inside that, You . On your computer, You will be your own Windows username, so your prompt will show your name there.
- > is the ready sign. It marks the end of the prompt. Everything after it is yours to type.
After the > there is a blinking cursor. That blinking is cmd waiting. It will wait all day. Nothing happens until you type something and press Enter.
NOTE Prompts differ from computer to computer, because usernames and folders differ. When this book shows C: \Users\You> , read You as "your username". What matters is the shape of the line, not the name in it.
What Happens When You Press Enter
Every command you will ever run in cmd follows the same four steps:
One command, start to finish. This same cycle repeats for every line you type.
- You type a command and press Enter.
- cmd reads the whole line you typed.
- cmd runs the command. The command does its job.
- The prompt returns. The result appears above a fresh prompt, and cmd is ready for the next command.
That is the whole rhythm of working in cmd: type, Enter, read the answer, type again. There is nothing else hiding behind it.
Your First Commands
Time to type. Open cmd using whichever way you like, and try each command below. In this book, lines you type are shown in a bat block, and what cmd prints back is shown right after the word "Output:" in a plain block. Type the command exactly as shown and press Enter.
echo: Making cmd Say Something
echo prints text to the screen. Whatever you type after the word echo and a space comes back at you:
echo Hello! Output:
Hello! Try your own words:
echo I am learning cmd. Output:
I am learning cmd. echo looks like a toy. It is not. Printing text is how scripts report what they are doing, and you will use echo in nearly every script in this book.
One surprise: type echo with nothing after it:
echo Output:
ECHO is on. With no text to print, echo instead reports whether command echoing is on or off. You will find out in the next chapter why that setting matters. For now, just remember: echo plus words prints the words, and echo alone prints that report.
ver: Which Windows Is This?
ver prints the version of Windows on the computer:
ver Output:
Microsoft Windows [Version 10.0.xxxxx.xxxx] The x's above are stand-ins. Your computer prints real numbers in those spots, and the numbers on your computer will almost certainly be different from your friend's. That is normal. The shape of the line is what ver always gives you: the words Microsoft Windows , then the version inside square brackets, with an empty line before and after.
NOTE This book never prints a "real" version number for ver , because there is no single right one. Your build number depends on your computer and its updates. If your numbers differ from a screenshot you see somewhere, nothing is wrong.
cls: A Clean Screen
After a while, the window fills up with old commands and old answers. cls (short for "clear screen") wipes the window clean:
cls There is no output to show. The screen empties, and a fresh prompt sits at the top, waiting. Nothing is deleted except the clutter on screen. Your earlier work is not lost; only the mess is gone.
help: cmd's Own Manual
cmd knows many commands, and you are not expected to remember them all. help prints the list:
help The list is long — it fills more than a screen — and it starts with the line "For more information on a specific command, type HELP command-name", followed by the command names in alphabetical order, each with a one-line description.
The useful part is asking about one command. Try:
help echo Output:
Displays messages, or turns command-echoing on or off.
ECHO [ON | OFF]
ECHO [message]
Type ECHO without parameters to display the current echoing setting. Read that slowly and it matches what you just did: echo with a message prints the message, and echo with nothing prints the current setting. Whenever you meet a new command in this book, help plus the command name is a good habit. The manual is already on your computer.
date /t: Today's Date, Just the Date
The date command on its own is for setting the date: it shows the current date and then asks you to type a new one. That question surprises beginners, and typing something at that point changes your computer's date. If it ever happens to you by accident, just press Enter without typing anything and nothing changes.
When you only want to see the date, add /t :
date /t cmd prints one line with today's date and asks nothing. The exact look of that line — day first or month first, with or without the day's name — depends on your computer's region settings, so this book does not show a sample of it. Run it and see your own computer's style. The /t stands for "tell me only", and a few other commands use the same idea.
The Mistake Everyone Makes in the First Ten Minutes
Sooner or later you will mistype a command. Say your finger slips and you type:
ehco Hello! Output:
'ehco' is not recognized as an internal or external command,
operable program or batch file. Read it plainly: cmd is saying "I do not know a command called ehco ". Nothing broke. Nothing was deleted. cmd simply refused a word it does not know and gave the prompt back to you.
This message is your friend. When a command "does nothing", look for this message first. Nine times out of ten, a letter is wrong, missing, or swapped.
GOTCHA Commands must be spelled exactly right, but they do not care about capital letters. ECHO , Echo , and echo are the same command to cmd. A wrong letter fails; a different case does not.
So What Is a Batch File?
Everything so far, you typed one line at a time, and cmd ran each line the moment you pressed Enter.
A batch file turns that around. Instead of typing commands live, you write them into a plain text file, one command per line, and save the file with a name ending in .bat . Then you tell cmd to run the file, and cmd runs the commands one by one, top to bottom, just as if you were typing them and pressing Enter after each one.
Here is a tiny batch file, saved as ch01-hello.bat :
@echo off
echo Hello from the Command Prompt!
echo This little file ran all by itself. Run it, and cmd prints:
Output:
Hello from the Command Prompt!
This little file ran all by itself. Do not worry about the first line yet — @echo off gets its own full explanation in the next chapter, where you will build this file yourself, step by step. For now, hold on to the idea: a batch file is a saved list of commands that cmd works through from the top line to the bottom line.
Why do people write these files? The same jobs come up again and again:
- A teacher who renames a whole folder of photos before every class trip, the same way each time.
- An office worker who copies the day's work folder into a backup folder every evening.
- A gamer who starts three programs at once before playing, every single time.
- Anyone who has ever typed the same command wrong for the fourth time and watched it fail.
A batch file fixes all of that. You write the commands once, carefully. After that, the file does the typing for you — exactly the same way, every time, with no slips. Running a job becomes a double-click instead of a page of typing.
PRO TIP A good rule for spotting a job worth turning into a batch file: if you have done it by hand three times and you will do it again, it wants to be a file.
Try It Yourself
- Open the Command Prompt from inside a folder, using the address bar trick (Way 3). Look at the prompt
and work out which drive and which folder cmd is standing in.
Answer Open any folder in File Explorer, click in the address bar, type `cmd`, and press Enter. The prompt shows that folder's path. For example, if you opened your Documents folder, the prompt will read something like `C: \Users\You\Documents>` — your username in place of `You`. The drive is `C:`, the folder is the one you were looking at, and the `>` at the end means cmd is ready.
- Using only commands from this chapter, make cmd print the word Ready , then a blank line. The second
command is a small variation on one you have seen.
Answer
echo Ready
echo. Output:
Ready The second command is `echo` with a full stop pressed right up against it and nothing else. `echo.` prints an empty line. You will use it a lot in the next chapter to space out a script's output.
- You type echo on its own, with nothing after it, and press Enter. What does cmd print, and why?
Answer cmd prints `ECHO is on.` With no message to print, `echo` reports whether command echoing is switched on or off instead. It is not an error — it is `echo` answering a different question, and the next chapter shows why that on/off setting matters when you run batch files.