Change the cmd.exe command prompt.
Syntax PROMPT [text] Key text : a text string.
The prompt text can be made up of normal characters and the following special codes:
$A & (Ampersand) $B | (pipe) $C ( (Left parenthesis) $D Current date $E Escape code (ASCII code 27) $F ) (Right 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 NT 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 highly dependent on 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. 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.
Limitations for prompt length are 400 symbols in Windows XP / Vista and 511
The maximum length of a prompt string (in Widows 7 and above) is 511 characters. If a longer prompt is set it will be silently truncated to the first 511 symbols. The dollar codes count as 1 character.
Hitting the limit also produces different results in XP/Vista and the fresher versions: 1.On XP/Vista it produces error message 2.On 7 and above it just only takes the first 511 symbols.
Simulate an HP-UX style prompt with the computername and the current folder on separate lines:
Display the time, backspacing to hide the milliseconds:
Restore the default prompt:
PROMPT is an internal command. If Command Extensions are disabled the commands $M and $+ are not supported.
â€œAll actions are judged by the motive prompting themâ€ ~ Muhammad
SETX – Set an environment variable permanently.
Powershell: Create a function called Prompt (save in Profile.ps1 to make permanent)
Equivalent bash command (Linux): variable $PROMPT_COMMAND
“« Back to Glossary Index