Programming Field

DOS/Command Prompt Reference

This page includes 100 or more command references for MS-DOS Prompt and Windows Command Prompt. Some command references have samples for the prompt and the batch files.

The list of commands by purpose, such as ‘File operations’ and ‘Text operations,’ is available here.

Command list

Commands/Programs [Alphabetical order]
ABCDEFGHIJKLMNOPQRSTUVWXYZ
A
Adddrv[DOS][W9x]Loads character device files into the current session. Sample:
adddrv C:\WINDOWS\COMMAND\DOSIME.SYS
Details:Adddrv
Append[DOS]Configures files in the specified directory to be treated as if they exist in the current directory. Sample:
append c:\data;d:\data
Details:Append
AssocDisplays or modifies file associations. Sample:
assoc | findstr /R =txtfile$
Details:Assoc
AttribDisplays or changes file/directory attributes. Sample:
attrib +R +H +S c:\command.com
Details:Attrib
B
Break[DOS]Changes the configuration for handling Ctrl+C input during file access and similar operations. Sample:
break on
Details:Break
C
CallExecutes a batch program from a batch program without terminating. Or executes subroutines. Sample:
call :exec_cmd foo.exe %1
Details:Call
CdChanges the current directory. Sample:
cd /D D:\MyData\Music
Details:Cd, Chdir
ChcpDisplays/changes the code page for the current session. Sample:
chcp 65001
Details:Chcp
ChdirChanges the current directory. Sample:
chdir /D D:\MyData\Music
Details:Cd, Chdir
Chev[DOS][W9x]Switches the language (mode) for the current session. Sample:
chev US
Details:Chev
ChkdskConducts a disk check. Sample:
chkdsk C: /scan
Details:Chkdsk
ChkntfsSchedules volume check for the next startup. Sample:
chkntfs /C C:
Details:Chkntfs
ChoiceDisplays choices on the screen and prompts for input. Sample:
choice /C YN /M "Continue"
Details:Choice
ClipCopies the provided input to the clipboard. Sample:
set /P MY_TMP="Hoge" < NUL | clip
Details:Clip
ClsClears all output in the screen. Sample:
cls
Details:Cls
CmdExecutes the Windows Command Interpreter (Command Prompt). Sample:
cmd /S /C "mklink /S foo bar"
Details:Cmd
ColorChanges the prompt color. Sample:
color 0F
Details:Color
Command[DOS][W9x]Executes the MS-DOS command interpreter (MS-DOS prompt). Sample:
command /K setting.bat
Details:Command
CompCompares files in binary. Sample:
comp data1.txt data2.txt
Details:Comp
CompactManages the compression status of files on NTFS. Sample:
compact /S:D:\document /C
Details:Compact
ConvertConverts a volume with FAT/FAT32 file system to NTFS. Sample:
fsutil file createnew Q:\ph.bin 16777216
convert Q: /FS:NTFS /CvtArea:ph.bin /NoSecurity
Details:Convert
CopyCopies the file(s). Sample:
copy /Y source.txt dest.txt
Details:Copy
CurlPerforms data transfer using URLs. Sample:
curl -LO http://www.pg-fl.jp/music/Simple.sf2
Details:Curl
D
DateDisplays and changes the system date. Sample:
echo.| date
Details:Date
DelDeletes the file(s). Sample:
del test.*
Details:Del, Erase
Deldrv[DOS][W9x]Unloads character device files that have been loaded into the current session. Sample:
deldrv
Details:Deldrv
Deltree[DOS][W9x]Deletes the directory tree (directory and files/directories in its directory). Sample:
deltree /Y test
Details:Deltree
DirDisplays the file list in the directory. Sample:
dir C:\WINDOWS /W
Details:Dir
DiskcompCompares the (floppy) disks. Sample:
diskcomp A: A:
Details:Diskcomp
DiskcopyCopies the (floppy) disk. Sample:
C:
diskcopy A: A:
Details:Diskcopy
DoskeyConfigures input assistance settings for the prompt. Sample:
doskey delall=del *.*
Details:Doskey
DriverqueryOutputs a comprehensive list of installed drivers on the system. Sample:
driverquery /FO TABLE /NH /V | findstr /I /C:"usb"
Details:Driverquery
E
EchoOutputs text to the screen. Also toggles prompt display. Sample:
echo Hello!
Details:Echo
EndlocalEnds localization of environment changes. Sample:
endlocal
Details:Endlocal
EraseDeletes the file(s). Sample:
erase test.*
Details:Del, Erase
ExitExits the prompt, batch programs, or subroutines. Sample:
exit /B 0
Details:Exit
ExpandExpands files compressed in a specific format. Sample:
expand -R D:\SETUP\APP.EX_ C:\PROGRAM
Details:Expand
F
FcCompares files. Sample:
fc /C /N /W data1.txt data2.txt
Details:Fc
FindSearches for the string from the file. Sample:
find /n "the" document.txt
Details:Find
FindstrSearches for the string from the file. More advanced search options than Find are available. Sample:
findstr /c:"the more" document.txt
Details:Findstr
ForExecutes a command for each files or texts matching with the specified pattern. Sample:
for /F "usebackq delims=" %t in ("D:\My Files\hoge.txt") do @foo.exe "%t"
Details:For
ForfilesExecutes a command on files/directories located under the specified directory. Sample:
forfiles /P %CD%\data\2017 /S /M *.xml /C "\"D:\My Tools\Parser.exe\" Parser.exe\" /I @path /O \"%CD%\output\2017\""
Details:Forfiles
FormatFormats a drive. Sample:
format H: /FS:NTFS
Details:Format
FtpConnects to the FTP server and performs file transfers. Sample:
ftp ftp.microsoft.com
Details:Ftp
FtypeManages the file types used in file associations. Sample:
ftype | find /I "notepad.exe"
Details:Ftype
G
GotoMoves execution to the specified label in batch files. Sample:
goto OnExit
Details:Goto
H
HelpDisplays the command's help. Sample:
help robocopy | more
Details:Help
HostnameOutputs the hostname for the computer on which the Hostname program is executed to the screen. Sample:
for /f "delims=" %N in ('hostname') do set "MY_HOSTNAME=%N"
Details:Hostname
I
IcaclsDisplays or changes Access Control List (ACL). Sample:
icacls PrivateSchedule /reset
icacls PrivateSchedule /grant:r Luminas:F /grant:r BUILTIN\Administrators:F /inheritance:r
Details:Icacls
IfExecutes a command when specified condition is met. Sample:
if exist E:\MySetup.ini goto Finish
if "%errorlevel%"=="255" echo Fatal error has occurred.
Details:If
IpconfigPerforms operations related to network adapters and IP addresses. Sample:
ipconfig /flushdns
Details:Ipconfig
L
LabelDisplays or changes the volume label of a drive. Sample:
label G: User Drive
Details:Label
Lh[DOS]Loads a resident program into upper memory. Sample:
LH mscdex.exe /D:CDROM1
Details:Lh, Loadhigh
Loadhigh[DOS]Loads a resident program into upper memory. Sample:
LOADHIGH mscdex.exe /D:CDROM1
Details:Lh, Loadhigh
M
MdCreates a new directory. Sample:
md C:\Programs\MyProg
Details:Md, Mkdir
Mem[DOS]Outputs the memory usage status of resident programs. Sample:
mem /c /p
Details:Mem
MkdirCreates a new directory. Sample:
mkdir C:\Programs\MyProg
Details:Md, Mkdir
MklinkCreates a symbolic link, a hard link, etc. Sample:
mklink NewFile.ini D:\home\target.ini
Details:Mklink
ModeConfigures devices such as CON, COMn, etc. Sample:
mode CON cp select=65001 > NUL
Details:Mode
More commandDisplays the long output per screen. Sample:
type C:\Config.sys | more
Details:More command
MountvolManages volume drive assignments. Sample:
mountvol X: \\?\Volume{00000000-1111-2222-3344-5566778899aa}
Details:Mountvol
MoveMoves the file(s). Sample:
move *.log C:\Logs\Current
Details:Move
O
OpenfilesChecks and closes open files among those shared remotely. Sample:
openfiles /query /v
Details:Openfiles
P
PathDisplays or changes the path(s) to search for programs. Sample:
path C:\DOS;C:\WINDOWS
Details:Path
PauseStops (pauses) the execution and prompts for any key input. Sample:
pause > NUL
Details:Pause
PingSends packets to a specified host to verify network connectivity, response time, and packet loss. Sample:
ping -t 192.168.1.1
Details:Ping
PopdRestores Pushd's directory change just before. Sample:
popd
Details:Popd
PrintPrints (sends) text to the printer. Sample:
print myData.ps
Details:Print
PromptSets/changes the prompt display. Sample:
prompt [$d $t$h$h$h] $n$g
Details:Promt
PushdChanges the current directory. The current directory can be restored by calling Popd. Sample:
pushd \\myserver\files\20120922
Details:Pushd
Q
Qbasic[DOS]Launches MS-DOS QBasic. Sample:
qbasic /RUN C:\APPS\GAME.BAS
Details:Qbasic
R
RdDeletes the directory. Sample:
rd /S /Q D:\Documents\data\2020
Details:Rd, Rmdir
RecoverAttempts to recover (restore) the file. Sample:
recover D:\Data\foo.xls
Details:Recover
RegOperates on the Windows Registry. Sample:
reg query "HKCU\Software\My Company\MyApp" /v Version
Details:Reg
RemDoes nothing. Used for writing comments in batch files. Sample:
rem Version 2012-06-17
Details:Rem
RenChanges the name of the file. Sample:
ren C:\Foo\document.txt hello.txt
Details:Ren, Rename
RenameChanges the name of the file. Sample:
rename C:\Foo\document.txt hello.txt
Details:Ren, Rename
ReplaceReplaces files in a specified directory with files from another directory. Sample:
replace D:\*.log E:\logs /U
Details:Replace
RmdirDeletes the directory. Sample:
rmdir /S /Q D:\Documents\data\2020
Details:Rd, Rmdir
RobocopyCopy files and directories using the specified conditions. Sample:
robocopy P:\Logs Q:\Backup\Logs /E /IF access*.* error*.* /XF access_ignore_*.* error_ignore_*.*
Details:Robocopy
RunasRuns the program with a user and privileges different from the current user. Sample:
runas /user:Administrator "powershell Start-Process cmd.exe -Verb runas"
Details:Runas
S
Scandisk[DOS][W9x]Performs a check on the disk (drive) and repair the file system. Sample:
scandisk /ALL /AUTOFIX /NOSAVE
Details:Scandisk
SchtasksManages tasks, which execute programs at specific timings. Sample:
schtasks /create /tn CheckUpdate /tr D:\home\updater.exe /sc daily /st 17:00
Details:Schtasks
SetDisplays or modifies environment variables. Sample:
set PATH=D:\bin;%PATH%
Details:Set
SetlocalBegins localization of environment changes, making environment variable changes or etc. temporary. Sample:
setlocal enableextensions enabledelayedexpansion
Details:Setlocal
Setver[DOS][W9x]Manages the MS-DOS version table and changes the MS-DOS version presented to a specific program. Sample:
setver C:\TOOLS\CHECKER.EXE 4.00
Details:Setver
SetxAdds or modifies values in user-specific/system-wide environment variable settings. Sample:
setx MYHOME D:\MyHome
Details:Setx
ShiftShifts parameters, specified to the batch program, and enables to use 10 or more parameters. Sample:
shift
Details:Shift
ShutdownShuts down or restarts the computer. Sample:
shutdown /s /t 0
Details:Shutdown
SortSorts each line of input data and prints the result. Sample:
sort < foo.txt > bar.txt
Details:Sort
Start commandLaunches the program or executes the default processing for the file. Sample:
start /wait notepad.exe /p hoge.txt
Details:Start command
SubstAssigns a specific directory to a virtual drive. Sample:
subst W: D:\MyDir\Files\work
Details:Subst
Switch[DOS]Switches the language environment of MS-DOS. Sample:
switch
Details:Switch
Sys[DOS][W9x]Copies files for an MS-DOS boot disk to a drive. Sample:
sys C: A:
Details:Sys
SysteminfoDisplays system information. Sample:
for /f "tokens=1,* delims=:" %%A in ('systeminfo') do if "%%A"=="BIOS Version" call :UseBIOSVersion %%B
Details:Systeminfo
T
TakeownSets the owner of the file/directory to the current user. Sample:
runas /user:Hana "takeown /F note.txt"
Details:Takeown
TaskkillTerminates the currently running program. Sample:
taskkill /F /IM notepad.exe
Details:Taskkill
TasklistDisplays a list of currently running programs. Sample:
tasklist /FI "imagename eq excel*"
Details:Tasklist
TimeDisplays and changes the system time setting. Sample:
echo.| time
Details:Time
TimeoutWaits for a specified duration (waiting for input). Sample:
timeout 5 /NOBREAK > NUL
Details:Timeout
TitleChanges the title of the prompt window. Sample:
title Hello, world
Details:Title
TreeDisplays subdirectories (or files) in the tree format. Sample:
tree /A /F D:\Document > d_doc.log
Details:Tree
TskillForcefully terminates the running process (program). Sample:
tskill notepad
Details:Tskill
TypeOutputs the file content. Sample:
type setup.txt | more
Details:Type
TzutilDisplays or changes the time zone setting. Sample:
tzutil /S UTC
Details:Tzutil
V
VerPrints the version of MS-DOS or Windows. Sample:
ver
Details:Ver
VerifySets whether to verify writing a file to a disk. Sample:
verify ON
Details:Verify
VolDisplays the volume label and volume serial number. Sample:
vol C:
Details:Vol
W
WaitforSends/receives signals to wait for. Sample:
waitfor /S 127.0.0.1 /SI HogeSignal
Details:Waitfor
WhereSearches for files that match the pattern and outputs their locations. Sample:
set "MYDIRS=D:\Scripts;E:\All Data\Commands"
where $MYDIRS:post_exec
Details:Where
WhoamiOutputs the username, group names, and permissions based on the current session. Sample:
whoami /priv /fo csv /nh
Details:Whoami
X
XcopyCopies files and directories. Sample:
xcopy /Y /Q /S /E E:\My\Directory\*.* F:\Foo\Bar\Directory\
Details:Xcopy
* Command is an internal command, Command is an external command (program).
* Command is treated as an internal command only in Command Prompt and batch files running under Command Prompt environments.
Pipe/redirection symbols
|[Pipe] Passes the output of the left command as input to the right command. Sample:
echo Y| del "%TEMP%\*.*"
Details:‘|’
<[Input redirection] Passes specified file contents as input to the command. Sample:
sort < document.txt
Details:‘<’
>[Output redirection] Writes the output of the command to the specified file. Sample:
foo.exe > out.txt
Details:‘>’
>>[Append redirection] Appends the output of the command to the specified file. Sample:
echo First Line> out.txt
echo Second Line>> out.txt
Details:‘>>’
Special characters/symbols, device file name etc.
* Please see also ‘Pipe/redirection symbols’.
@Suppresses echo-back of commands in batch files. Sample:
@gcc.exe -o main main.c
Details:‘@’
:Defines a label in batch files. Sample:
:Error
Details:‘:’
;Used to write comments in Config.sys file. Sample:
; any comment
Details:‘;’
%Used to retrieve values of environment variables and batch program parameters. Sample:
%SystemRoot%\system32\notepad.exe
Details:‘%’
!Used for the delayed environment variable expansion. Sample:
if "%VAR%"=="" (
    call hoge.bat
    if "!VAR!"=="" (
        echo Failed.
        exit /B 1
    )
)
Details:‘!’
^Treats the following character as a regular character. Or treats multiple lines as one-line command line. Sample:
foo.exe -f file1.txt ^
        -f file2.txt ^
        -f file3.txt ^
        -f file4.txt
Details:‘^’
&Executes two or more commands in a row. Sample:
setlocal enabledelayedexpansion
set FOOVAR=hello & echo !FOOVAR!
Details:‘&’
||Used to execute the another command when the command fails. Sample:
hoge.exe || echo !ERRORLEVEL!
Details:‘||’
&&Used to execute the another command when the command succeeds. Sample:
call :piyo && echo !RETVAR!
Details:‘&&’
( )Treats multiple commands like one command. Sample:
if "%MYVAR%"=="Hello" (
    echo Hoge
    echo Piyo
)
Details:‘( )’
*Represents ‘any string of length 0 or more’ as a wildcard character. Sample:
dir *. /w
Details:Wildcards
?Represents ‘any single character’ as a wildcard character. Sample:
copy *.in? \Backup
Details:Wildcards
CONA device file of ‘console’. Sample:
type CON > save.txt
Details:CON
NULA device file of ‘an empty file’ Sample:
pause > NUL
Details:NUL
AUXA device file used to communicate with the device through the default serial port. Sample:
type modemcmd.txt > AUX
Details:AUX, COMn
COMnA device file used to communicate with the device through the serial port corresponding to the specified number. Sample:
type modemcmd.txt > COM2
Details:AUX, COMn
PRNA device file used to communicate with the device (printer) through the default parallel port. Sample:
echo cmdtext > PRN
Details:PRN・LPTn
LPTnA device file used to communicate with the device through the parallel port corresponding to the specified number. Sample:
print /D:LPT2 doc.txt
Details:PRN・LPTn
Common environment variables
COMSPECContains the path to the command interpreter. Sample:
%COMSPEC% /K setenv.bat
Details:COMSPEC
PATHContains the path(s) to search for programs when executing. Sample:
set PATH=%PATH%;C:\MyDir
Details:Path
PATHEXTContains a list of extensions to attempt when an extension is omitted. Sample:
set PATHEXT=%PATHEXT%;.PL;.PY;.RB
Details:PATHEXT
PROMPTContains the prompt setting. Sample:
set OLD_PROMPT=%PROMPT%
Details:Prompt
TEMPContains the path to the directory used for temporary data. Sample:
set TEMP=X:\Work
Details:TEMP, TMP
TMPContains the path to the directory used for temporary data. Sample:
set TMP=X:\Work
Details:TEMP, TMP
Notes
  • On this site, ‘Windows NT series’ means Windows NT/2000/XP or later environments or ‘cmd.exe’ environments (Not all Windows versions are researched). ‘command.com’ environment may be differ from ‘cmd.exe’ environment.

Other contents