Chapter 3 – Understanding the prompt
When you start the Command Prompt program, the first thing you'll see on your screen is this:
C:\>
That is the actual command prompt itself. But what does the prompt do? What do all those symbols mean? We'll discuss how to understand and alter the prompt in this chapter.
WHAT IS THE PROMPT?
The "prompt" that gives the Command Prompt its name is the first thing you see when you launch the Command Prompt program. What is it? To put it simply, its a series of characters that indicates the computer is ready to accept commands from you. Nowadays, you know that a computer has booted up and is ready to run programs when you see the Windows desktop. But in the days of DOS, you only knew the computer was ready when you saw the DOS prompt appear on the screen.
The basic prompt in the modern Command Prompt looks something like this:
C:\>
Alternatively, it can have additional directory paths within itself - generally, when you launch a new Command Prompt session, it opens in your home folder, so it will probably look something like this:
C:\Users\USERNAME>
What does this all mean?
If you remember the previous chapter on drive letters, the "C" in the prompt refers to the C drive, your computer's hard drive. You can change the selected drive in Command Prompt by typing the drive letter followed by a colon. For instance, if you wanted to switch from the C drive to the D drive, you would type this and his enter at the prompt:
D:
And then prompt would change from this:
C:\>
To this:
D:\>
If the first letter in the prompt indicates the currently selected drive, the characters after the drive show the current directory and subdirectory on the selected drive. In a prompt that looks like "C:\>", that indicates you are in the root directory of the C drive, since the "\" character represents the root directory of a drive. And as you change the current directory, the prompt changes as well to show the current directory. For instance, if you change from the root directory to the Program Files directory, the prompt will look like this:
C:\Program Files>
As you change into deeper and deeper subdirectories, the prompt will accordingly become longer and longer.
The final character in the prompt, the greater than sign (>), indicates the end of the prompt and the location of the cursor. Any commands you type into the prompt will appear to the right of the greater than sign.
CHANGING THE PROMPT
The default prompt configuration is good enough for most people. However, if you would prefer to customize the prompt to show additional (or less) information, you can do so with the PROMPT command. The PROMPT command lets you alter the appearance of the prompt, while customizing it however you wish.
To test it out, type this command at the prompt:
PROMPT Hello!
You'll notice that the command prompt immediately changes from "C:\>" to "Hello!" While having the prompt say "Hello!" seems quite friendly, it nonetheless contains no useful information. To change it back, type this command at the modified prompt:
PROMPT $P$G
The prompt will then change back to the more familiar "C:\>".
As you might guess, the PROMPT command lets you do more than simply put friendly (or snarky) messages in the command prompt. The PROMPT command responds to a series of variables, and will modify the prompt to display information based on those variables. In the above example, the $P variable refers to the current location, and the $G variable refers to the greater than sign. So when you issue a PROMPT command with the variables in this order, you'll return to the prompt to its default state:
PROMPT $P$G
Here are some the more useful variables you can use with the PROMPT command to enhance the default command prompt:
-$D adds the current date to the prompt.
-$C adds a left parenthesis.
-$F adds a right parenthesis. You can use this in conjunction with $D to place information provided by the other variables with a set of parentheses.
-$N displays the currently selected drive.
-$P displays both the currently selected drive and the currently selected location on that drive.
-$T shows the current time.
-$V shows the Windows version number.
You can get a complete list of variables for the PROMPT command by using it with the /? switch:
PROMPT /?
(As we mentioned earlier, using the /? switch with any command will provide a list of options for that command. It's a useful switch to remember, in case you can't recall the switches available for any one command.)
Let's combine these variables in a few separate examples. (You can always return to the default prompt with the PROMPT $P$G command if you make a mistake.) Say you wanted the prompt to show the current date and time along with the drive and location. You would use this command:
PROMPT $P$G$D$T
This would alter the prompt to show the current date and time:
C:\>Sun 08/28/201115:08:14.47
However, that prompt looks rather cluttered. It might work better if you put a space between the date and the time with this command:
PROMPT $P$G$S$D$S$T
The resultant prompt would look like this:
C:\> Sun 08/28/2011 15:09:17.24
By playing around with the PROMPT command and its variables, you can customize the prompt to your liking.
CHANGING THE TITLE BAR
By default, the title bar of the Command Prompt window reads simply "Command Prompt." You might want to change it to show more information - if you have multiple Command Prompt windows open, changing the title bar is a quick reminder to let you know what task you are performing in each window. Or you could simply change it for your own amusement.
You can change the text of the title bar with the TITLE command. For instance:
TITLE Hello!
This will change the text of the Command Prompt window from "Command Prompt" to "Hello!"
CHANGING THE TEXT AND BACKGROUND COLOR
When you launch a new Command Prompt window, it shows white text on a black background. This a throwback to the old DOS prompt, which always booted up with white text on a black background (or green text on a black background) in order to reduce the chance of the old-style tube monitors burning the text onto the screen. Fortunately, tube monitors have becoming increasingly rare (I don't miss carrying them from building to building) and flat-panel LCD monitors have taken their place.
Reading white text on a black background for a long period of time can put strain on your eyes. If you want to change the color of the Command Prompt's text or background, you can do so with the COLOR command.
The COLOR command generally looks like this:
COLOR 07
If you entered this command at a default Command Prompt window, nothing would happen. Why not? COLOR 07 sets Command Prompt to use white text on a black background. The first digit sets the background color, and the second digit sets the text color. So, COLOR 07 sets Command Prompt to use a black background and white text.
Here is the complete list of codes to use with the COLOR command:
-0, Black.
-1, Blue.
-2, Green.
-3, Aqua.
-4, Red.
-5, Purple.
-6, Yellow.
-7, White.
-8, Gray.
-9, Light Blue.
-A, Light Green.
-B, Light Aqua.
-C, Light Red.
-D, Light Purple.
-E, Light Yellow.
-F, Bright White.
For instance, if you wanted to set the Command Prompt to use white text on a black background, you would use COLOR with these options:
COLOR 70
Or, if you wanted to set Command Prompt to use green text on a black background (to make it look a bit like "The Matrix" science fiction movies), you would use this command:
COLOR 02
Finally, if you make a typo and the Command Prompt is displaying some hideous mixture of colors, like blue text on a black background, simply type the COLOR command without any options. Entering COLOR without any codes after it will reset the prompt back to white text on a black background.
No comments:
Post a Comment