A more verbose prompt in Windows CMD Shell

I work in Windows and often use Command Prompt (cmd.exe) as the command shell. This post touches on the new command prompt I use.


The default prompt in Command Shell is the full path to the folder that you are in followed by a greater than sign (>) so it looks like: d:\tools> or something similar. Windows lets you change the prompt by using the prompt command. If you do prompt /? in the console, you will see the options that are available to customise the prompt. The default prompt comes from $p$g which translates into the path ($p) followed by the greater than sign ($g). Let’s look at the more verbose prompt that I currently use.

The New Prompt

I like to see the following in my command prompt:

  • The current date and time
  • The folder we are in
  • End with a ‘$’ instead of ‘>’ and then a space.

Here is what it looks like.

In short, you just need to do: prompt $D$S$B$S$T$H$H$H$S$B$S$P$G$_$$$S – throw it into a command file and call it when you want to change the prompt if you don’t want to make it permanent (see the next section for information on how to make it permanent). The explanation is shown in the picture below.

It’s a 2-line prompt with each line created from the parts in the yellow highlight and the $_ shown in blue provides the newline to split the prompt onto the second line. The main components are date ($d), time ($t), space ($s), pipe ($b), dollar sign ($$) and greater-than symbol ($g).

There is probably just one things to explain: $t returns the time down to 2 places of decimal which is a bit excessive for the command prompt at least for me. That’s why I add $H three times which is the equivalent of doing backspace 3 times (or deleting the last 3 characters) – so, the time stamp that came back as 23:17:33.81, with the last 3 characters deleted, becomes just 23:17:33 – you could delete more or fewer if that suits you better, but at a seconds level is just nice for me.

Also, note that the command prompt is not showing a real-time changing clock – it just shows the time when the prompt was rendered. I like that because it reminds me of the time at which I ran a command.

Further Reading

Hope this helps. Most of the necessary information is based on doing prompt /? and following the information there.

To permanently change the prompt, you can set the Environment Variable prompt to the format that you want and it will change. You can do this either using the Windows GUI or by using set (e.g. set prompt=$$) to change it in the current session, setx (e.g. setx prompt=$$) to change it for the current user (applies to the next console Window you open), or by using setx /M (e.g. setx /M prompt $$) to change it for all users.

Note that when you use set, you separate the key and value, you need to use an ‘=’ sign to separate the two (e.g. set prompt=$p$g) but when you use setx, the key and value are separated by a space (e.g. setx prompt $p$g).

You can find more on StackOverflow or you can read up more information about setx and its variations.

I wrote this up so that I remembered what I had done (and why) – if this helps you, that’s great! If you have any comments or caught an error that slipped by, please let me know in the comments below.

comments powered by Disqus