PROMPT – Windows CMD Command
Change the cmd.exe command prompt.
1 2 3 4 5 |
Syntax PROMPT [text] Key text : a text string. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
The prompt text can be made up of normal characters and the following special codes: $A & (Ampersand) $B | (pipe) $C ( (Opening parenthesis) $D Current date $E Escape code (ASCII code 27) $F ) (Closing parenthesis) $G > (greater-than sign) $H Backspace (erases previous character) $L < (less-than sign) $M Display the remote name for Network drives $N Current drive $P Current drive and path $Q = (equal sign) $S (space) $T Current time $V Windows version number $_ Carriage return and linefeed $$ $ (dollar sign) $+ Will display plus signs (+) one for each level of the PUSHD directory stack |
The default prompt is $P$G (drive/path followed by > )
The PROMPT command is tied to the %PROMPT% environment variable, editing the variable will lead to the same result as using the PROMPT command (e.g. PROMPT $P$G is the same as SET PROMPT=$P$G)
If the %PROMPT% variable is deleted, the prompt will automatically revert to the default.
To set the CMD prompt for all sessions, set a permanent environment variable (SETX) with the appropriate prompt text. e.g.
SETX PROMPT $M$_$P$G
The prompt variable only holds the prompt definition, the final prompt characters are calculated by the CMD console.
The maximum length of a prompt string is 511 characters. If a longer prompt is set it will be silently truncated to the first 511 symbols.
The dollar codes each count as 1 character.
Errorlevels
When CMD Command Extensions are enabled (the default)
If the prompt was successfully changed %ERRORLEVEL% = unchanged, typically this will be 0 but if a previous command set an errorlevel, that will be preserved (this is a bug).
If prompt could not be changed %ERRORLEVEL% = 1
If an attempt is made to set a prompt using a dollar sign followed by any character, not in the list of codes above, then everything after that dollar sign will be ignored.
PROMPT does not error if passed invalid switches PROMPT /Z /invalid – it will just set them as part of the prompt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Examples Display the UNC path whenever you are using a network drive (mapped with NET USE) PROMPT $M$_$P$G Simulate an HP-UX style prompt with the computername and the current folder on separate lines: PROMPT=$p$_%username%@%computername%:. Display the time, backspacing to hide the milliseconds: PROMPT=$T$H$H$H$G$S Restore the default prompt: PROMPT $P$G Save a backspace character (obtained via the $H option) into the variable %BS%. (source) For /F %%A in ('Echo PROMPT $H ^| cmd') do Set "BS=%%A" PROMPT is an internal command. If Command Extensions are disabled the commands $M and $+ are not supported. |
I am so happy to read this. This is the kind of manual that needs to be given and not the accidental misinformation that’s at the other blogs. Appreciate your sharing this greatest doc.
Very nice info and right to the point. I don’t know if this is in fact the best place to ask but do you people have any thoughts on where to employ some professional writers? Thank you 🙂