Windows Command Prompt in 15 Minutes
 


This tutorial describes a few of the most important commands that you will use on the Windows command prompt.


 

What is Command Prompt?
 

Learning the Command Prompt also provides a gradual transition to Unix and Linux systems, which are prevalent in science, engineering, and industry. The Command Prompt works at a lower level than Windows. This means that you will have more control over the machine. The disadvantage is that it is less user-friendly.

To launch Command Prompt select Start -> Run and type cmd in the box.

The Command Prompt shows up as a black terminal window. The command prompt should look something like:

C:\>

This is where you type commands. The boldface type below (that follows the command prompt) is what you should type as you work through this tutorial. Windows does not care if you use upper or lower case. That means that command cd is the same as CD. It also means that, in Windows, file HelloWorld.java is the same ashelloworld.java. This is not true in the system to which you will be submitting your files.

 

Some Useful Commands

 

 

Working with Files and Directories
 

You can also use Command Prompt commands to organize files into a directory hierarchy. These commands are equivalent to corresponding commands that you access via the Windows point-and-click interface. It is useful to be familiar with both interfaces for managing files.

 

Redirection
 

Two important abstractions in Command Prompt are standard input and standard output. By default standard input is your keyboard, and standard output is your computer screen. For example, in Assignment 1, we write a program CenterofMass.java that reads input using StdIn.java and writes output using System.out.println(). To run our program, the user types the command "java CenterofMass" and enters double type values in triplets: xposition yposition mass from the keyboard. The results appear in the terminal window.

C:\introcs\loops> java CenterofMass
0 0 10
1 1 10
0.5  0.5  20

 

Piping
 

Another useful abstraction is piping.  Piping is when the output of one program is used as the input of another program. For example, suppose we want to view the output of a program, but there is so much that it whizzes by on the screen too fast to read. (The program RandInts.java prints out a bunch of random integers.) One possible way to accomplish this is to type the following two commands.

C:\introcs> java RandInts > temp.txt
C:\introcs> more < temp.txt
Note that more will work by redirecting the file temp.txt to standard input (as is done here) or by simply using the filename (as is done at the beginning of the document). Instead, we could do this in one line using the pipe symbol '|'
C:\introcs> java RandInts | more

This is often useful when debugging a program, especially if your program goes into an infinite loop and you want to see the first few values that it prints.


 
Written by Jake Brenner, Donna Gabai and Kevin Wayne.