prompt - Customize the Command Prompt
Table of Contents
The prompt command changes the text (the prompt) shown at the start of each line in Command Prompt.
By default, the prompt looks like C:\Users\taro>: the current folder followed by >. With prompt, you can show the time or drive name, move the input area to the next line, and otherwise shape it to suit you.
Basic Syntax of the prompt Command
prompt [<text>]
For <text>, combine ordinary characters with special codes that start with $. If you omit the argument, the prompt returns to its default.
prompt $P$G
$P stands for the current folder and $G for >. This is the same form as the default prompt.
Special Codes
| Code | What it displays |
|---|---|
$P | Current drive and folder (e.g., C:\Users\taro) |
$N | Current drive (e.g., C:) |
$G | > |
$L | < |
$C | ( |
$F | ) |
$+ | One + for each level of the pushd stack |
$D | Current date (format depends on regional settings) |
$T | Current time |
$V | Windows version |
$_ | Line break |
$S | Space |
$$ | $ |
$Q | = |
$B | | (pipe symbol) |
$A | & |
$E | Escape character (ASCII code 27; used to set colors) |
$H | Backspace (erases the preceding character) |
$M displays the remote name (the connection target) when the current drive is a network drive. For other drives, it displays nothing.
Examples
Move the input area to the next line
With a deep folder hierarchy, the prompt gets long and leaves little room to type. Use $_ to move the input area to the next line.
prompt $P$_$G$S
After running it, the prompt looks like this.
C:\Users\taro\Documents\Projects\sample
>
Show the time
prompt $T$S$P$G
Because you can see when each command was run, this is handy for checking how long a process took. The $T output includes fractions of a second, such as 12:34:56.78.
Show the date and time
prompt [$D$S$T]$S$P$G
Add color (ANSI escape sequences)
Combining $E with an ANSI escape sequence lets you color the prompt.
prompt $E[32m$P$E[0m$G
$E[32m: turns the following text green$E[0m: resets the color
Colors work in environments that support ANSI escape sequences, such as Command Prompt on Windows 10 or later and Windows Terminal. In unsupported environments, characters like ←[32m may be displayed as-is.
The Change Applies Only to the Current Window
A prompt changed with prompt returns to normal when you close that Command Prompt window, because the command rewrites an environment variable called PROMPT. You can check the current setting with the following command.
echo %PROMPT%
Save the setting and use it every time
To get the same prompt in every new Command Prompt window, save the PROMPT environment variable with setx.
setx PROMPT "$P$_$G$S"
A value saved with setx takes effect in Command Prompt windows opened afterward. To apply it to the current window as well, also run prompt $P$_$G$S.
For details on setx, see the related article.
Restore the default
Running prompt with no argument restores the default prompt.
prompt
To remove a setting saved with setx, delete PROMPT in the environment variable settings screen, or overwrite it with the default ($P$G) as follows.
setx PROMPT "$P$G"
Notes When Using It in a Batch File
If you run prompt inside a batch file, the prompt in the calling window stays changed after the batch file ends. To change it only temporarily, wrap it in setlocal and endlocal.
@echo off
setlocal
prompt [Testing]$S$P$G
cmd /k
endlocal
Changes made in a batch file are discarded at endlocal (or when the batch file ends). Since the prompt is only visible interactively, the example opens a new screen with cmd /k to show it. Running this batch file opens a new cmd whose prompt is [Testing] C:\...>. When you leave it with exit, the original prompt is unchanged.
cmd /k keeps an interactive Command Prompt open from a batch file. You can also pass a command at startup, as in cmd /k prompt $P$G.
Summary
| Goal | Command |
|---|---|
| Move the input area to a new line | prompt $P$_$G$S |
| Show the time | prompt $T$S$P$G |
| Display in green | prompt $E[32m$P$E[0m$G |
| Check the current setting | echo %PROMPT% |
| Save the setting | setx PROMPT "$P$_$G$S" |
| Restore the default | prompt |