PROMPT

Change the appearance of 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  (           (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.

PROMPT is an internal command. If Command Extensions are disabled the commands $M and $+ are not supported.

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"

“All actions are judged by the motive prompting them” ~ Muhammad

Related commands

SETX - Set an environment variable permanently.
Equivalent PowerShell: Create a function called Prompt (save in Profile.ps1 to make permanent).
Equivalent bash command (Linux): variable $PROMPT_COMMAND


 
Copyright © 1999-2024 SS64.com
Some rights reserved