MS-DOS Command Reference Cheat Sheet
As a PeopleSoft admin and a PeopleSoft developer, you will have plenty of occasions to create batch files and having competitive MS-DOS skills will go a long way helping you write super efficient code.
There is a great book on Windows Command-Line Pocket Reference if you’d like to use.
In this post, you will find the DOS commonly used commands as well as a DOS Complete Reference. Right click and save as to download.
If you would like to check our great collection of reference cheat sheets, click here.
Commands may be typed in upper or lower case. Here, they are specified in upper case to distinguish them from other input. Commands have a particular format. Some can be used simply by typing the command name only, as in:
DIR : Displays a listing of files in the current directory.
COPY : file-a is copied to file-b
Commands can also be qualified by the use of options. Options are preceded by a / sign. A simple example of the use of an option is with the DIR command. DIR can be qualified by /P or /W. Thus the commands:DIR DIR /W DIR /P
result in listings presented in a different format as detailed later.
COPY Make a copy of a file or merge files together.
COPY original-file destination-file
where original-file and destination-file are file names, separated by a space.
The command can be used to merge several files into one file since the original-file parameter can be a list of filenames separated by the + symbol. For example:
COPY file1 + file2 file3
would copy file1 and file2 into file3.
Note that the file names used in the copy command must include the file extension if it exists. So if you were copying a fortran program called first.for, for example, you would need to include the .for extension in the filename.
DEL Delete a file.
You are asked to confirm that you really want to delete the file. Note that the name must include the file extension. It is possible to use a ‘*’ character in a filename to match any sequence of characters. This feature is very useful when deleting unwanted files with identical extensions.
DIR : Obtain a list of the files stored in a directory.
If used without options this command will give a list of files in the current directory, including any extension (e.g. .for), and their size.
DIR /P : The same information will be displayed page by page with the message:
strike a key when ready
at the end of each page.
DIR /W : The listing is of names and extensions only and in a more compact format across the page.
DISKCOPY A: A:
where A: denotes the drive the disks will be loaded into. When a copy of your disk is generated in the computer’s memory, the computer tells you to remove the first or source disk and insert the disk, which is to become the copy (the target disk).
Insert the target disk and press ENTER. If the second disk is not formatted it will be formatted automatically. The source disk should be write protected using the tab in the corner in case you mistake it for the target disk (see the chapter on using disks).
LIST Obtain a printed listing of a file. LIST filename
where filename is the file to be printed. If the printer is busy, or if you don’t need a printed copy, you can use the TYPE command to view a file on the screen.
You could also use an editor such as DOS Edit to display a file, in which case, as a bonus, you would then be in a position to correct any errors you might notice. Remember that the file name must include the file extension. So if you want to print your Pascal program called first you would need to use:
REN oldname newname : Rename oldname to newname file. Filename can also be qualified with a path or file location, for example: A:\dir1\dir2\filename
TYPE filename : Display filename on the monitor screen. If you are looking at a long file, you will need to press the PAUSE key to stop continuous scrolling. Press the space bar to continue scrolling when you have read the screen.
FORMAT A: Format disk in drive A (Warning: You will lose data)
DOS Command ListingIn the following section, alternative options are separated by the ‘!’ character. Arguments are optional unless in italics. ‘cwd’ stands for ‘Current Working Directory’.
DOS commands are not case sensitive. Some commands have switches; these must be preceded by a forward slash (/). Pathnames may be preceded by a drive letter as in ‘X:pathname’ and if no drive or pathname is given the current directory is assumed.
ATTRIB +!-r +!-a pathname
display, or set!clear Read-only or Archive attribute
display, or turn on!off increased level of ^C detection
CHDIR (CD) path : display, or change working directory
CHKDSK pathname (A: drive only) check disk or file logical structure /f – fixproblems encountered /v – verbose; displays filespecs
CLS : clear screen
COMMAND path cttydev
run nested CLI from path with I/O device cttydev /e:# – set environment size #
/p – do not invoke another CLI
/c command – run command and then enter
COPY pathname pathname or
COPY pathname + pathname
copy or concatenate files
/v – verify writes
/a!b – preceding and all subsequent files are ascii! binary (* filenames in source(s) and target are matched one-to-one.)
change MS-DOS I/O device
display and/or set date (numerical country-dependent format)
DEL ! ERASE pathname
delete file(s) – prompts if pathname is *.*
display directory – filename and/or ext default to * /p – paginate
/w – multi-column
DISKCOPY drive: drive:
copy disk sector-by-sector rather than file-by-file
exit nested CLI
FIND “string” pathname
find and display lines containing string in file /v – lines NOT containing string
/c – count lines only
/n – display line numbers also
FORMAT drive: (A: drive only) /1 – single sided
/4 – use double rather than high density (40 tracks) /8 – use 8 sectors of each track
/n:xx – specifies xx sectors per track
/t:yy – specifies yy tracks
/v – prompt for volume label, up to 11 characters /f:720 – format at 720 kb
LABEL drive: label (A: drive only)
display, or edit volume label – 11 characters excluding most specials
MKDIR (MD) path make directory
DOS Command Reference 5
6 DOS Command Reference
interactively configure various options
paginates screen output
e.g. type filename | more
display or set command search path(s) to be used after cwd
resets default to cwd only
reset or set prompt.
Characters (each prefixed by $) mean:
$=$, t=time, d=date, p=cwd, v=version, n=drive, g=>, l=<, b=!, _=CRLF, s=leading space, e=ESC (for ANSI driver)
RENAME (REN)pathname pathname
rename file(s) within a drive – wildcards are matched one-to-one
RMDIR (RD) path
remove empty directory
display all, set or clear MS-DOS variable – accessed as %variable%
enable networked multi-access file locking
/f:nbytes – nbytes per file, need about 20 bytes per file, default 2048
/l:nlocks – nlocks per file, default 20
SORT pathname pathname
sort lines of file alphabetically, ignoring case, to file or stdout; reads stdin by default
/r – reverse order
/+n – on n’th character in each line, default is first
SUBST drive: path (A: drive only)
display substitutions, or substitute path by virtual drive
SYS drive: (A: drive only)
copy hidden MS-DOS .sys files from default drive
TIME hours:minutes : display and/or set time using 24-hour format
TYPE pathname : output contents of a file, with tab spacing of 8
VER : display MS-DOS version
display, or set!clear disk write verification
display disk volume label
XCOPY pathname pathname copy directory tree
/a!m – if archive bit set ! also clears in source
/d:date- modified on or after date only
/s!e – copy subdirectories if not empty ! even if empty /p – prompt
- /v – verify
- /w – wait for keypress
If renamed to MCOPY it determines automatically whether target is file or directory.
Full details of all DOS commands can be seen by following the command with the switch /? For example,
gives a listing of all DIR options.
DOS commands are stored in a template and previous commands can be recalled, character by character enabling editing as required.
Batch File Commands
The arrow keys may also be used to recall the previous command.
All DOS commands may be used in batch files. Additionally, the following commands are useful for more advanced batch processes.
Arguments for batch files are accessed as ‘%1’ to ‘%9’.
display echo status, turn echoing on!off (default on) or display message
FOR %%C IN (SET of items) DO command
C is any character other than 0-9, SET is e.g. list of files
is accessed by the following keys:-
get next character from template
get characters up to but excluding character C get remaining characters from template
skip one character in template
skip characters up to but excluding character C clear command line
toggle overwriting of template
copy command to template for re-editing
put ^Z in new template
F1 F2 C F3 del F4 C ESC INS F5 F6
GOTO LABEL : LABEL is any line of text, usually preceded by colon (:) in first column, which makes MS-DOS ignore it other than as a label. Terminates if label not found
IF ERRORLEVEL number command
command executed if previous command returned exit code >= number
IF string1 == string2 command
command executed if strings match may be negated by NOT before condition
IF EXIST filename : command executed if file exists. It may be negated by NOT before condition
PAUSE comment : comment displayed only if echo on
REM comment : remark – ignored by MS-DOS
shift arguments – allows access to more than 9
Several special characters may be used when referring to directories and files:
File Comparison Utility
The FC command enables comparison of two files:
FC pathname1 pathname2
compare two files, or two wildcarded sets of files
- /a – abbreviate output of ASCII comparison
- /b – force binary comparison (byte-by-byte)
- /c – ignore case
/L – force ASCII comparison (line-by-line)
/Lb# – use line buffer of # lines
/n – display line numbers in ASCII mode
/t – do not expand tabs – default expands to spacing
/w – compress white space (tabs and spaces) to
single space (leading or trailing white space
/# – # lines must match to re-synchronize else
regarded different (default is 2)
8 DOS Command Reference
\ = . = .. =
root directory or a directory separator current directory
Wildcard characters may be used in filenames or extensions:
? = * = X: –
any tail or extension
switches to current working directory (cwd) on drive X.
Input and output from commands or programs can be redirected by using the following symbols:
> send output to…
>> append output to…
< take input from…
| pipe output to next input
pipe output from command a to input of command b:
command a | command b
send a directory listing to file filename: DIR > filename
DOS includes a full-screen editor invoked by the EDIT command (with or without a filename). To use this editor type:
The editor provides pull-down menus, operated by the keyboard or mouse, and a help facility. Note that any changes made to a file overwrites the original, no backup is created.
Using The DOS Editor
DOS input and output may be controlled by the following control key sequences. (^ = the CTRL key).
^C – ^H – ^J – ^N – ^P – ^S – ^X – ^Z –
abort current command
linefeed – physical newline to input long lines toggle copying of terminal output to printer toggle redirection of terminal output to printer suspend/restart terminal output
cancel current line, and output \-CR-LF
end of file
DOS Command Reference 9