CMD/DOS Essentials
First: The "Command Prompt", as it is officially known in Windows, is the legacy CLI (though it isn't going anywhere) provided by CMD.EXE which resembles the MS-DOS Prompt (provided by COMMAND.COM). CMD.EXE provides some built-in commands, and others are external .EXE commands - but we'll consider anything provided my Microsoft in MS Windows to be "built-in".
The CMD Command Prompt aka DOS Prompt carries a lot of legacy baggage, in fact most of the commands are made to operate identically to how they worked in MS-DOS, but with some enhancements. This is both a blessing and a curse.
There's less uniform standardization and consistency with "DOS" commands (even ones provided by Microsoft with Windows, due to legacy reasons) but even less so with random Console .EXE files you may download and run. (though many are trying to follow modern Linux/Bash/macOS standards)
To start the Command Prompt run cmd.exe
, or look for "Command Prompt" in your Start menu.
Type commands at the C:\>
prompt and press Enter after each.
Included Windows console commands (both CMD built-in commands and external .EXE commands) are often short
(dir
instead of "list directory" or md
instead of "make directory") and
sometimes cryptic (such as qwinsta
instead of "query windows station"); often because these commands
have been around since the days of MS-DOS and 8 character filename limits. Generally there is no regular pattern
all command names follow.
Get-Content
,
Set-Content
, etc) CMD/DOS commands usually wrap all verb/action functionality into the same
command, either using switches/options (like command.exe /add
or command.exe /remove
) or subcommands (like command.exe list
or command.exe edit -option
).dir
, copy
,
md
/mkdir
, ren
, del
, etc) meaning if you learn these you'll
be able to operate in both CLI Shells.regedit.exe
) however some may also have useful switches/options.PATH
environment variable.c:\windows\system32\inetsrv\appcmd.exe
,cd c:\windows\system32\inetsrv
) and then run appcmd.exe
Parameters/switches/options for CMD/DOS Commands are separated from commands with a Space and
usually a single dash - or slash /, as in -AH
or /B
.
/a value
-a:value
or -a=value
/ah
or /ahs
appending either H or HS
to /A/A
, the H or HS is just the value for /A
)--listall
/a /o /n
can be written
as /aon
or as /a/o/n
without spaces)git status
not /status or -status)git log --oneline -n 10
git
is the command for Git, the source code repository package. log
is a sub-command for Git. --oneline
is a
parameter for the "Log" sub-command. And -n
is another option for Log with
10
being the value passed to -n
Getting Help for CMD/DOS commands can also vary. A short list of the basic included Windows console commands
can be found by running help
but this by no means includes them all (mostly just the older legacy
MS-DOS derived commands).
Usually you need to pass a switch or option for DOS/CMD/Console .EXE commands to show their Help text. It can vary, but one of these should work:
-h
, /h
, --help
, /?
, -?
, or just ?
ping /?
If the Help Text is too long add | more
after, as in: chkdsk /? | more
. But don't just type the name of the command
with no switches to see what it may do until you've tried /?, /h, etc. because some commands will do something even with no options/switches. For example:
IISRESET
will restart all IIS Web Services if you provide no options, which may not be what you want/expect! iisreset /?
will show the help.
Sometimes you can just type the command with no options and it will provide help, but sometimes the command
doesn't require options and it just runs!
If this happens and it appears to hang (likely waiting for input) try pressing any of:
Ctrl+C, Ctrl+Z, or Ctrl+D to either cancel the
command or end the input.
While the meaning of console CLI switches/options/arguments can vary usually how they are represented in Help Text is fairly standard.
There's Tab completion only for files/directories at the CMD Command Prompt. Type a command and if you need
to specify a file/folder start typing the name and press the Tab key to cycle through all matching
files/folders. For example: type cd \win[press TAB]
and it will complete to
cd C:\Windows
Another trick you can sometimes use: the * wildcard. If it will match only one folder, as in
cd \win*
, it will resolve to the first folder starting with "win" in the root of the drive.
The Command Prompt is (generally) NOT Case Sensitive. You can type DIR
, dir
,
DiR
, etc.
To run a script you can just run it as any other built-in or external .EXE command, so long as it is in the
PATH
it will be found.
You can enter any CMD/DOS command at the prompt and test/build scripts one command at a time - that is: variables and whatnot persist between commands (but not between sessions - if you close the window everything not saved to a file is gone). However the Shell itself only has limited expression evaluation abilities, you can can't just type 2 + 2 and get back 4 like you can with PowerShell.