Back to 111 Main Page

Mobius strip

Using the Windows Command Prompt


Before Windows, Microsoft released a text-based operating system called MS-DOS. While DOS has largely expired, the usefulness of typing commands to the operating system remains. Not everything in your OS has a pretty clickable icon, and so the command line can grant you access to powerful features not used by casual users. The commands used to interact with Windows are generally the same as those that were used by MS-DOS (though more and more Unix commands are gradually being supported).

Opening the Command Prompt

In order to type commands, you need to first open the command prompt: Start -> Programs -> Accessories -> Command Prompt. This will open a new black window with a command prompt that shows the path to your current location in the computer's directory structure. It should look something like this:

C:\Documents and Settings\Zach>

(An alternative method is: Start -> Run..., and then type cmd and hit enter.)

Essential Commands

The path displayed by command prompt will tell you which directory you are currently in. The dir command (short for directory listing) will print a list of all files that are in the current directory. The information displayed includes each file's name, when it was last edited, and its file size. Listings that contain <DIR> (rather than a file size) are sub-directories (folders) of the current directory.
Usually you have to be in the same directory as the files you want to work with. To change directory, use the command cd. You must also specify the name of the subdirectory you want to move into. Example:
C:\Documents and Settings\Zach>cd Desktop

C:\Documents and Settings\Zach\Desktop>
This moves you down one level. To move up a level, use .. to stand for "the parent directory". Example:
C:\Documents and Settings\Zach\Desktop>cd ..

C:\Documents and Settings\Zach>

You can combine these to form longer path names relative to your current location, or you can use absolute (fully-qualified) names that start with a drive letter. Example:

C:\Documents and Settings\Zach>cd ..\..\windows

C:\WINDOWS>cd "C:\Documents and Settings\Zach"

C:\Documents and Settings\Zach>
(Depending on your system, you may have to put "quotes" around any path name that includes spaces.)
switching drives
If you have to switch to a different drive, just type the destination drive letter followed by a colon. Example:
C:\Documents and Settings\Zach>d:


C:\Documents and Settings\Zach>

Once you're in the right location, you can manipulate your files using commands such as java and javac.

These are only the barest of DOS commands. To learn what other common commands exist, type help. To learn more about a specific command, type the command name followed by /?, as in: dir /? You can also learn more by doing a search online for a DOS tutorial.

Some other commands that you should probably learn: cls, more, del, mkdir, and rename. (Be careful with del: deleting files at the command prompt bypasses the Recycle Bin, so deleted files are immediately gone forever.)

Tips and Tricks

Command History (up arrow)
When compiling code, it can be time-consuming to type the whole command and file name each time. Instead, press the up arrow on your keyboard. This will scroll through previous commands you've typed. You can edit them, or just hit enter to run that command again.
Auto-completion (tab)
If you type the first letter of the name of a file in the current directory and then hit the tab key, DOS will insert to rest of the name for you (so you don't have to type it). If there's more than one name that begins with the same letter, you can tab multiple times to cycle through them all.
Copying and pasting
If you need to copy something (such as an error message or program output) from the command prompt window: right-click with your mouse and select Mark. Now hightlight what you want to copy with the mouse and then right-click again. This copies whatever you highlighted to the system clipboard, and you can paste it from there into another window or application (as with normal pasting).
Killing a program (ctrl-c)
If a program is hanging or not responding, you can hold down the Ctrl button and press C to kill . (This is a faster alternative to closing the command window and then reopening it.)
Full screen (alt-enter)
Hold down the Alt key and press Enter to enter full screen mode. Repeat to return to a window. (Scare/impress your friends!)
Changing the initial directory
You can right-click the Command Prompt shortcut, go to Properties, and then edit which directory a new command prompt starts in. (Or, rather, you should create a copy of the default shortcut and then make such edits to the copy.)
Increasing the buffer size
Sometimes, if either the compiler or your program produces a great many lines of output, you won't be able to scroll up high enough to see the first line. To fix this, right click on the top bar of the Command Prompt window and go to Properties. Under the Layout tab, increase the value for the Screen Buffer Size: Height. 500 or 1000 lines should be sufficient. Run the command again and you should be able to scroll up high enough now.

Good luck using the command prompt!

~ztomasze Index : TA Details: ICS111: Command Prompt
Last Edited: 02 Mar 2010
©2009 by Z. Tomaszewski.