Get the Most from Command Prompt!

A Quick and Handy Guide

John S. Uebersax

Introduction

Not too long ago, all PCs (IBM compatibles, not Apples) ran the DOS operating system. This worked without windows. Just a dialogue system between user and computer, conducted via a one-line prompt, the command prompt.

For older users the figure below will remind them; for others it will be something new.

Command Prompt window

In many ways DOS was a better way to interact with the computer. With Windows you're just a user. But with DOS you're more like a system administrator, able to perform some high-level tasks easily.

Take a simple example. What if I want to delete all the files in a folder that have the extension .old from a given folder. With Windows I'd need to open Windows Explorer, navigate to the folder, sort the files by type, click on all with the .old extension, then delete them. But in DOS I'd just move to the folder, type the command:

      del *.old

and press enter. That's all. And this is just a very basic example of what can be done.

Though DOS as such is no longer a part of Windows, Microsoft has made a solid effort to maintain compatibility of Windows 98/NT/2000/XP/2003 with this earlier system. This is done with the Command Prompt window, which duplicates or emulates the MS-DOS environment.

Besides greater efficiency and flexibility for many routine tasks, another reason to learn about Command Prompt is that there is still much good software that was written for DOS and can only run in a Command Prompt window.

This page explains gives some simple tips to help use your Command Prompt.

return to top


Opening the Command Prompt Window

There are several ways to open the Command Prompt window (or MS-DOS window, if you're using Windows 98 or earlier).

Using a Desktop shortcut

Probably the best way is as follows. Click your Windows Start button, then click Programs. In Windows 98 you should see a program called MS-DOS prompt. In Windows NT/2000/XP/2003 you should be able to find Command Prompt under Accessories.

In either case, right-click the icon and select Send To then Desktop. This places a shortcut to the Command Prompt on your desktop. In the future you can open Command Prompt just by clicking this shortcut. You can also copy the shortcut to your taskbar.

You can even launch Command Prompt with a single hot-key (provided the shortcut is on your desktop). For this:

After this you can launch Command Prompt just by pressing ctrl+alt and this key.

Note, though, that this only works for shortcuts whose icons are on your desktop. If the shortcut is on your taskbar but not also on your desktop, the hot-key won't work.

Opening from Start/Run

With this method you click the Start button of your Windows task bar, then click Run. In the small dialog box (see below), after Open:, type command (for Windows 98 or earlier) or cmd (or "cmd.exe") then press OK.

 

Clicking a program icon

If you're in a real hurry, you can open a temporary Command Prompt window by just clicking on the icon of a program that runs in this mode. A potential problem, though, is that the window might close once the program finishes, and you won't see the results. (I am gradually modifying my programs so that the window remains open until the user presses a key).

return to top


Changing Window Size and Appearance

The first thing you might want to do is to change the size or appearance of the window. To change the size, right-click the Title bar, click Properties and then select the Fonts tab. You can select from a variety of font and window sizes. In newer Windows versions you can also do this by clicking the icon at the top left of the window.

By default, Command Prompt shows 25 lines. You can change the number of lines displayed by typing:

      mode con: lines=n

where n is 25, 43 or 50..

If you want a full-screen view, pressing alt+enter toggles between full-screen and window mode.

Changing the prompt

The command:

      prompt $p$g

will cause your current drive and directory to be shown with the prompt. This is a good idea. It's possible this is already included in your defaults. If not, just type this command or place it in your autoexec.bat file (see below).

Clearing the window

To clear the Command Prompt screen type:

      cls

return to top


Navigation

Navigation in Command Prompt is simple once you get the hang of it. To change the current disk drive, enter the letter of the drive followed by ':', for example:

      c:

followed by enter. (From here on we'll just assume the enter key is pressed after a command, and won't mention it each time).

The CD command lets you change the current directory (a directory is what Command Prompt calls a folder) To use the CD command you would type

      cd directoryname

If the directory name contains spaces, place the name in double quotes, e.g., cd "long directory name")

Shortcut commands

Navigation to commonly-used folders, or issuing other commonly typed commands, can be made easier with shortcut commands. For example, if I often use the folder c:\long_folder_name\

I could place the command

      cd c:\long_folder_name\

in a file called go.bat (the .bat extension means it is a batch file. For more about batch files below). Then, rather than issue the long cd command, I could simply type:

      go

and Command Prompt would go to that folder.

As you can see, this leads to the possibility of having several short, even 1-letter commands that take you to your more commonly used folders. (It's even possible to have entirely different "suites" of short or one-letter commands, which you can apply depending on whether you're doing word-processing, file-manipulations, programming, etc.)

Exiting Command Prompt

To close a Command Prompt window, just issue the command:

      exit

return to top


Paths

When a command is issued in Command Prompt, the computer first looks in the current folder for an executable file with the same name and an extension like .exe, .com or .bat. If it doesn't find one there, it then searches in other specified folders. The folders searched, and the order in which they are searched, can be controlled by the path command. For example, the command:

      set path=c:\;c:\windows;c:\tools

this means if I type a command (one that is not a standard DOS or Command Prompt command, that is), Command Prompt will first search the root folder (that is, c:\),then the c:\windows folder, and finally the c:\tools folder until it finds an executable program with the same name as my command.

Note above that no spaces are allowed after the word path.

return to top


Batch Files

Batch files give you a lot of control over your computer. A batch file is a list of Command Prompt commands, placed in a single file and executed with a single command. For example, suppose I want to sort delete all files in a folder with the .bak extension, list the files, and then edit the list in Notepad. This could be done by putting these lines in a file:

      del *.bak
      dir > files.txt
      notepad files.txt

in a file called "go.bat"

Now any time I want to issue these commands, I simply type:

      go

and they execute.

As this example above suggests, you can open Notepad from Command Prompt just by typing Notepad. (You might need to adjust your path to include the folder where the program notepad.exe resides.) In some versions of Command Prompt (Windows 98 and earlier, possibly others) you can also use the old DOS editor called EDIT.

return to top


File Manipulation

To See the files in a folder or directory, type:

      dir

To list files of a large folder or directory one screen at a time, type:

      dir /p

To copy one file to another:

      copy file1.ext file2.ext

To rename file1.ext to file2.ext

      rename file1.ext file2.ext

To delete a file:

      del file.ext

We can make use of the * wildcard specifier here. To delete all files with extension .ext

      del *.ext

or to delete all files in a directory with the letter 'e' in the file name:

      del *e*.*

return to top


To Edit Files

From Command Prompt you can start and use your Notepad editor. For example, type:

      notepad file.ext

This assumes that the folder that contains Notepad.exe is in your search path.

In Windows 98 and earlier versions, you can also use the old (but still useful) MS-DOS editor by issuing the command:

      edit file.ext

Cut-and-paste
If the toolbar is visible (if not, right click the Title bar, and check Toolbar), you can cut and paste to/from the Command Prompt window to other Windows applications.

To cut:

To paste this within a Command Prompt application:

To paste this within a Windows application (e.g., Word, Notepad):

return to top


Autoexec.bat

Upon starting, Command Prompt looks for a list of default initial commands in a file called autoexec.bat. This is usually found in your root folder (e.g., c:\), but it might be in your Windows folders (try searching for "autoxec.bat").

In this file you can place commands to execute each time you open Command Prompt.

In addition, you can have Command Prompt execute a second batch file upon starting. To use this, right-click the MS-DOS or Command Prompt icon, select Properties, choose the Program tab and enter the name of the batch file in the box that says Batch file--for example, startup.bat.

return to top


Advanced

It's possible to have Command Prompt keep a list of your recently executed commands. To scroll through previous commands, you then simply press the up-arrow and down-arrow keys. This avoids having to needlessly type the same command repeatedly.

To use this feature, just issue the command:

      doskey

You can also place this command in your autoexec.bat file, or in the optional batch file that launches when you open Command Prompt, so that it executes automatically.

This assumes that your search path (see above) includes the folder where the file doskey.com (Windows 98) or doskey.exe (later Windows versions) is located.

There are other features of doskey as well. For more information, you can check this link .

Opening Command Prompt in a specified folder

Here's an easy way to open a Command Prompt window in a specific folder:

Open Windows Explorer with a split-pane view. In the left pane, which shows a folder tree structure, highlight the folder you want. Press the Windows Start button and select Run. In the box beside Open: type command.com (Windows 98) or cmd.exe (later Windows versions). Command Prompt will now open, with the specified folder as the current directory.

I have verified that this works in Windows 98, but am not sure about later versions. However, for Windows 2000 or later, the following might work:

Open Windows Explorer and click View > Options > File Types. Locate Folder or File Folder and click Edit. Then click New. Type Command Prompt in the Action box, and type cmd.exe in the Application Used to Perform Action box. After this you can right-click a folder and select Command Prompt to open a Command Prompt window in that folder.

More navigation tricks

If you type:

it will move you up one folder level. To make things even simpler, you can make a simple batch file like:

and give this the name up.bat. Place this file in some folder on your search path. Then to move up a folder level you just need to type up and press enter.

Launching Windows programs

From Command Prompt you can launch most Windows programs, including Word, Excel, and Windows Explorer. You can even launch a program to play a music file. Just type the name of the excecutable file associated with the program, and, optionally, the file to be opened with the program. For example, the command:

will start the .mp3 file playing in Windows Media Player. Again, this assumes that Wmplayer.exe is in your search path.

Using this feature you can construct batch files as scripts to accomplish many complex tasks in Windows quite simply, and which launch with only a couple of keystrokes. From this you can see that Command Prompt is no mere throwback to an earlier era of computing--it's a sophisticated tool for power users.

For more information

There are lots of places on the web to learn more about Command Prompt. An especially helpful one is here.

return to top


To cite this article:
    Uebersax JS. Get the most from Command Prompt! Statistical Methods for Rater Agreement website. 2006. Available at: http://ourworld.compuserve.com/homepages/ jsuebersax/dos.htm. Accessed: month dd, yyyy.

Go to Agreement Statistics site
Go to Latent Structure Analysis site
Go to My papers and programs page

Last updated: 21 August 2006 (added counter)


(c) 2006-2009 John Uebersax PhD    email