The Command Prompt

There are a few threads I use every semester and I will be posting them on my blog for future reference. This blog covers accessing the command prompt.

To open the command prompt in windows:

  • Click on the Start menu button
  • Click on the Run.. button
  • Type in "cmd" and push OK
  • OR push the Windows-Key and the R button simultaneously
  • and type in "cmd" and push OK

To open the Terminal in OSX:
  • Open the Finder
  • Click on Applications
  • Click on Utilities
  • Then double-click on Terminal
  • It's useful to add Terminal to a more convenient location, to do so just drag and drop it onto your dock

Some of you may think that using the shell (command prompt/terminal) is the OLD way of using computers. Now-a-days, we use a window manager and graphical user interface such as Windows, Linux, or OSX. However, as a programmer its fairly typical to spend a lot of your time on a command-line interface. In this course it's fairly important because the The command-line is important in this course because it will help you compile, debug, and run your programs.

List the files in the current directory:
{WINDOWS} C:\DOCUME~1\Student > dir
{LINUX/OS} $ ls

Change to a new directory:
> cd folder1

Go back one directory:
List the files in the current directory:
> cd ..

Rename a file, from to
{WINDOWS} C:\DOCUME~1\Student > rename
{LINUX/OS} $ mv

Compile a Java file (.java) to ByteCode:
> javac

Run a Java program (after it's been compiled):
> java MyApp

In the Summer 2009 course, Andrew pointed out:

I'd also like to share the following keyboard shortcuts for the command prompt. Using the Up/Down arrow keys to recall previous entries is very helpful.
(Source: )

  • F1 – Repeat text typed in preceding line, one character at a time
  • F2 + Key – Repeat text typed in preceding line, up to first character matching key
  • F3 – Repeat text typed in preceding line
  • F6 – Place an end of file character (ˆZ) at current position of command line
  • F7 – Show all entries in command buffer
  • Alt + F7 – Clear all entries in command buffer
  • Ctrl + C – Used to interrupt the output of most command prompt applications
  • Left Arrow – Move back one character
  • Right Arrow – Move forward one character
  • Ctrl + Left Arrow – Move back one word
  • Ctrl + Right Arrow – Move forward one word
  • Up Arrow – Display previous command entered
  • Down Arrow – Display next command entered
  • Insert – Toggle insert/overtype mode (block cursor implies overtype mode)
  • Page Up – Display oldest command entered
  • Page Down – Display newest command entered
  • Home – Move to beginning of line
  • End – Move to the end of line
  • Esc – Erase current line