An internal command is part of the interpreter itself: it runs without starting a
program and has no file of its own. Anything else is an external command, a program
found through PATH. The viewer colours the internal commands below, and only where a command
can stand. Each command has its own page in Microsoft’s
Windows commands
reference; command /? prints help for any of them. Microsoft’s cmd page lists the commands
that change when command extensions are enabled: assoc, call, chdir,
color, del, endlocal, for, ftype,
goto, if, mkdir, popd, prompt,
pushd, set, setlocal, shift and start.
Commands for scripts
| Command | Purpose and switches |
|---|---|
rem | A comment (Lexical structure) |
echo | echo text shows text; echo on and echo off turn command echo on and off; echo alone shows the setting. @ in front of any command hides that command. echo., echo: and echo( print a blank line (no space before the dot, says Microsoft). Use echo:%var% so that an empty variable does not print “ECHO is off” |
pause | Prints “Press any key to continue . . .” and waits |
cls | Clears the screen |
title text | Sets the console window title |
color bf | Sets the console colours from two hexadecimal digits, background then foreground (0 black, 1 blue, 2 green, 3 aqua, 4 red, 5 purple, 6 yellow, 7 white, 8 gray, 9 light blue, A light green, B light aqua, C light red, D light purple, E light yellow, F bright white); color alone restores the defaults |
prompt text | Sets the command prompt: $A &, $B |, $C (, $D date, $E escape code, $F ), $G >, $H backspace, $L <, $N current drive, $P drive and path, $Q =, $S space, $T time, $V version, $_ line feed, $$ $; $M network name of the drive and $+ directory stack depth (reported) |
set, setlocal, endlocal | Variables |
if, for, else | Control flow |
goto, call, shift, exit | Parameters and labels; exit [/b] [code] ends cmd.exe or, with /b, the batch file or subroutine |
verify [on | off] | Turns the check that files are written correctly on or off. verify other (an invalid argument) is used to set a non-zero ERRORLEVEL to test for extensions |
break [on | off] | Extended Ctrl+C checking on DOS; kept for compatibility and does nothing in cmd.exe |
ver | Shows the operating system version |
start | Starts a program in a new window: start ["title"] [/d dir] [/i] [/min | /max] [/separate | /shared] [/low | /normal | /high | /realtime | /abovenormal | /belownormal] [/node n] [/affinity mask] [/wait] [/b] command args. The first quoted word is the window title |
Files and folders
| Command | Purpose and switches |
|---|---|
cd, chdir | Show or change the current folder; cd /d x:\path also changes the drive. cd.. and cd\ work without a space. With extensions, quotes are not needed around names with spaces |
md, mkdir | Make a folder; with extensions it makes every missing folder in the path |
rd, rmdir | Remove a folder: /s removes the tree, /q does not ask |
pushd, popd | Change folder and remember the old one on a stack, and go back; pushd on a network path maps a temporary drive letter |
dir | List a folder: /a[:attrs] (D folders, H hidden, S system, R read-only, A archive, I not indexed, L reparse points, with - to negate), /b bare, /c thousands separator, /d wide columns, /l lower case, /n long names on the right, /o[:order] (N name, E extension, S size, D date, G folders first, - reverses), /p pause, /q owner, /r streams, /s subfolders, /t[:field] (C created, A accessed, W written), /w wide, /x short names, /4 four-digit years. The DIRCMD variable sets default switches |
copy | Copy files: copy a+b c joins files; /a text, /b binary, /d allow an encrypted file to be decrypted, /v verify, /n short names, /y overwrite without asking, /-y ask, /z restartable, /l copy a link itself |
move | Move or rename files and folders: /y overwrite without asking, /-y ask |
ren, rename | Rename a file or folder; the new name is a name without a path, and wildcards work |
del, erase | Delete files: /p ask for each, /f force read-only, /s in subfolders, /q quiet, /a[:attrs] select by attribute |
type | Show a text file; several names and wildcards are accepted |
mklink | mklink [/d | /h | /j] link target: a file symbolic link, /d a directory symbolic link, /h a hard link, /j a junction |
path | Show or set the search path: path dir;%path%; path ; clears it |
assoc, ftype | Show or set the file type of an extension (assoc .txt=txtfile) and the command of a file type (ftype txtfile=notepad.exe %1) |
vol | Show a drive’s label and serial number |
date, time | Show and set the date and time; /t only shows it without asking for a new one |
chcp | Show or set the console code page (Encodings). In cmd.exe this is a separate program, chcp.com, and an internal command of MS-DOS |
Commands of COMMAND.COM only
These are internal to the DOS shell (MS-DOS and Windows 9x) and are not in cmd.exe, and the
viewer colours them: ctty (change the console device), lh and
loadhigh (load a program into upper memory), truename (the real name of a
path), lfnfor, lock and unlock (Windows 9x). break and
chcp belong here as well as in cmd.exe.
External commands often used
These are programs, not part of the interpreter; none are coloured. They are in Microsoft’s command reference.
| Command | Use |
|---|---|
find, findstr | Search text; findstr takes regular expressions and sets ERRORLEVEL 0 for a match |
sort, more | Filters for pipes |
xcopy, robocopy | Copy trees of files; robocopy exits with a bit mask of results, where values below 8 are success |
attrib, icacls, takeown | File attributes and permissions |
choice | Waits for one of a set of keys and returns its number as ERRORLEVEL (1 for the first) |
timeout, ping | timeout /t n waits n seconds; ping -n n+1 127.0.0.1 >nul is the older way to wait |
reg, setx, wmic | Registry, permanent environment variables and WMI queries |
tasklist, taskkill, sc, net | Processes, services and the network |
cmd, powershell, cscript, wscript | Other interpreters called from a batch file |
where, whoami, hostname, systeminfo | Information |
doskey, mode, tree, fc, comp, label, subst | Console and disk utilities |
How a command name is looked up
The name is checked against the internal commands first (so a file called dir.bat is run only
as dir.bat or with call of the full name), then against files in the current folder, then in
each folder of PATH, trying each extension of PATHEXT
(File structure). A built-in command name with an
extension, such as set.exe, is not the built-in. The viewer treats word.ext in
command position as a program name.
Not described
Known, not yet covered
- Reference: the switches of the external commands (
xcopy,robocopy,findstr,choice,timeoutand others) are not given; each has a page in Microsoft’s reference. - Viewer: none of the external commands is coloured, and command switches (
/s,/q) are plain.
Unknown
- Reference: the switch lists above are written from the commands’ own help and Microsoft’s command pages for
cmd.exe; those forstart,dir,copy,del,mklink,promptand the DOS-only commands were not re-checked against a run of the commands for this page, and the$Mand$+prompt codes and the exact set of COMMAND.COM-only commands are reported, not confirmed.