DOS Commands
DOS Commands
DOS Interface
The user interface with the DOS operating system is very simple. You type commands line-by-line on an
undecorated computer screen. All that you see to start with is a simple designation of what directory you are in,
like C:\> for the normal root directory.
Type the letter of the drive and a colon and press ENTER to change to the named drive.
d:
D:>
cd or chdir
Change current directory. Displays the current working directory when used without a path parameter.
cd
displays the current working directory on the current drive.
cd f:
displays the current working directory on F:.
cd directory
changes the working directory on the current drive to directory.
chdir e:directory
changes the working directory on E: to directory.
cd ..
changes the working directory to the parent directory (up one directory level).
cd \
changes the working directory to the root (top level) directory of the current drive.
cls
Clears the screen.
Cls
copy
Copies files from one location to another. The destination defaults to the current directory. If multiple
source files are indicated, the destination must be a directory, or an error will result.
Syntax:
copy filespec [destination]
Files may be copied to devices. For example, copy file lpt1 sends the file to the printer on LPT1. copy
file con outputs file to the screen ("console"), which can also be done using type file. Devices
themselves may be copied: copy con file takes the text typed into the console and puts it into file,
stopping when EOF (Ctrl+Z) is typed.
Files may be concatenated using +. For example, copy file1+file2 file_cat will concatenate the files
and output them as file_cat. There are two switches to modify the command's behaviour, /a (text mode,
1
the default) and /b (binary mode). In text mode, copy will stop when it reaches the EOF character; in
binary mode, the files will be concatenated in their entirety, ignoring EOF characters.
Examples of usage:
copy /a alpha.txt + beta.txt gamma.txt
copy /b alpha.mpg + beta.mpg gamma.mpg
del or erase
Deletes one or more files.
del filename
erase filename
Options
*.* All files in current folder
*.* /s all files in current folder and sub folders.
dir
Lists the contents of a directory.
The dir command typed by itself, displays the disk's volume label and serial number; one directory or filename
per line, including the filename extension, the file size in bytes, and the date and time the file was last modified;
and the total number of files listed, their cumulative size, and the free space (in bytes) remaining on the disk. The
command is one of the few commands that exist from the first versions of DOS.
dir [drive:][path][filename] [parameters]
Most commonly used parameters of dir include:
/W : Displays the listing in wide format, with as many as five filenames or directory names on each line.
/P : Pause at every page
/S : Also look in subdirectories
/Axx: Display files with the specified attributes only
/Oxx: Modifies sort order
/B : Uses bare format (no heading information or summary)
> [drive:][path][filename] : To Store Result in a text file;(c:\dir > c:\fileList.txt)
Possible attributes for the A parameter are D (directories), R (read-only files), H (hidden files), A (files/directories
with the archive bit on), and S (system files). The prefix - negates an attribute; attributes can be combined (e.g.
/A:DA means directories with the archive bit on).
Possible sort orders are N (name), S (size), E (extension), D (date and time), A (last access date), and G (group
directories first). The prefix - reverses the order.Other less commonly used parameters of dir include:
echo
Prints its own arguments back out to the DOS equivalent of the standard output stream. Usually, this
means directly to the screen, but the output of echo can be redirected like any other command. Often used
in batch files to print text out to the user.
echo this is text Outputs 'this is text'
echo. Outputs a blank line
Another important use of the echo command is to toggle echoing of commands on and off in batch files.
echo on turns on echoing of commands
echo off turns off echoing of commands
echo text > filename
2
Echo can also be used to append to files directly from the console, again by redirecting the output stream:
echo text >> filename
To type more than one line from the console into a file, use copy con (above).
exit
Exits the current command processor. If the exit is used at the primary command, it has no effect unless in
a DOS window under Microsoft Windows, in which case the window is closed and the user returns to the
desktop.
exit [/B]
/B When used within a batch script, exits the script without closing the calling DOS
window
find
A filter to find lines in the input data stream that contain or don't contain a specified string and send these
to the output data stream. Find may also be used as a pipe.
find "keyword" < ''inputfilename'' > ''outputfilename''
Searches for a text string in a file or files.
find [/V] [/C] [/N] [/I] "string" [[drive:][path]filename[ ...]]
/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
"string" Specifies the text string to find.
[drive:][path]filename Specifies a file or files to search.
If a pathname is not specified, FIND searches the text typed at the prompt
or piped from another command.
help
Gives help about DOS.
help 'command' would give help on a specific command. By itself, it lists the contents of DOSHELP.HLP.
Help for a specific command invokes the command with the /? option.
md or mkdir
Makes a new directory. The parent of the directory specified will be created if it does not already exist.
md directory
move
Moves files or renames directories.
move filename newname
move driveletter:\olddir driveletter:\newdir
Example of usage:
move c:\old c:\new
rd or rmdir
Remove a directory, which by default must be empty of files for the command to succeed (the /s flag
removes this restriction).
rd directory
ren
Renames a file. Unlike the move command, this command cannot be used to rename subdirectories, or
rename files across drives.
ren filename newname
You can rename files in another directory by using the PATH parameter:
ren [path]|[filename] [newfilename]
An example could be:
ren c:\Windows filex.txt filey.txt
Mass renames can be accomplished by the use of wildcards. For example, the following command will
change the extension of all files in the current directory which currently have the extension htm to html:
ren *.htm *.html
3
sort
A filter to sort lines in the input data stream and send them to the output data stream.
sort < inputfilename > outputfilename
Color
Sets the default console foreground and background colors.
color [attr]
attr Specifies color attribute of console output
Color attributes are specified by TWO hex digits -- the first corresponds to the background; the second the
foreground.