How to Change Kali Terminal Prompt Color

  • by

The environment variable PS1 (Prompt String One) holds the string that is being displayed as a command or shell prompt in the terminal emulator program Terminal. The prompt string is embedded (interspersed) with color tags in the form of

where x is a display attribute (normal, dim, bold, italics, etc) and y is the color code.

Changing the value or content of PS1 during a terminal session quickly changes the displayed prompt, however, the changes are lost once the terminal session is closed. To make the changes permanent, the hidden file named .bashrc located in the user’s home directory must be edited to reflect the changes in the prompt string.

Displaying the Value of PS1



Changing the Prompt

The prompt string can be made as simple as a single character like a dollar sign ($) or a hashtag sign (#). Or it can be any text string you may want. To change the prompt string, assign a new value to PS1.

To enter a string with spaces or non-printable characters, enclose the string with single (‘) or double (“) quotes.

Figure 1 – Examples of Customized Prompt

The Default Shell Prompt

The default shell prompt, besides being a cue for entering a shell command in a terminal session, is also used to convey a lot of information about the system. Take for an example the default Kali Linux shell prompt,

Figure 2 – Default Kali Linux Terminal Shell Prompt

The default shell prompt is in red, a warning sign. It indicates that the terminal user has administrative privileges or root privileges. It means that the user may, and can, mess up the system with improper commands like deleting files necessary for Kali’s normal operations.

It also shows the current user root, the host name kali, the current working directory, the home directory represented by the tilde sign (~), and finally, the hashtag sign (#) indicating a priveleged user as opposed to an ordinary user which is usually handed a prompt with a dollar sign ($).

Understanding the Cryptic PS1

To incorporate meaningful information on the shell prompt, bash, the shell interpreter, uses a special set of characters called escape characters , to encode information in the prompt string. See the table (Bash Prompt Escape Characters) below for the complete list of escape characters that are recognized by bash.

Escape Character CodeMeaning
\wWorking directory
\$Display a hashtag if uid=0 (user is root) or else display a dollar sign ($)

Let’s try this one:

The resulting prompt (rootkali~#) is close to the default prompt (root@kali:~#). Let us now insert the hashtag sign (@) sign between the words “root” and “kali” and also insert the colon sign (:) between the word “kali” and the tilde sign (~):

The resulting shell prompt is now the same as the default prompt, only, without the colors.

As mentioned above the color tag is in the form of:

where x is an attribute and y is the color code.

Going back to our last shell prompt,

we’ll add the color tag for red (31) with bold (1) attribute to make the words “root@kali” bold red,

add the color tag for blue (34) with bold (1) attribute before the tilde sign,

and finally, insert the color tag for white (37) with normal (0) attribute after the tilde sign,

The resulting code will be:

Now, we have the Kali’s default shell prompt.


To summarize, the shell prompt string is stored in the environment variable PS1. The string is composed of escape characters with meanings as defined in the table Bash Prompt Escape Characters. It also contains color tags in the form of,

as defined in the Attribute and Color Codes table.

Dissecting Kali’s Default Prompt

The Kali Linux Terminal’s default shell prompt as quoted at the very start of this post is represented by the string,

which is the output of the command:

The configuration string up to the curly right braced “}” takes effect only when a user changes the apparent root directory by using the command “chroot”.

Since we are not chroot-ing, we’re interested only on the part of the environment string past the curly right braces “}”, which is:

Based on our discussion above, here is the dissection of the said prompt:

\[Start of color information.
\033[01;33mBold Yellow
\]End of color information.
\uDisplay the current user name
@Display the “@” sign.
\hDisplay the host name.
\[ Start of color information.
\033[00mColor information (See table below).
\]End of color information.
:Display the colon sign(“:”).
\[Start of color information.
\033[01;34mBold Blue
\]End of color information.
\wDisplay the current working directory (tilde sign “~”)
\[Start of color information.
\]End of color information.
\$If user is root, display “#”, else display “$”

Table 2. Bash Prompt Escape Characters

Escape CharacterDescription
\aA bell character.
\dThe date, in "Weekday Month Date" format (e.g., "Tue May 26").
\D{format}The format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required.
\eAn escape character.
\hThe hostname, up to the first ‘.’.
\HThe hostname.
\jThe number of jobs currently managed by the shell.
\lThe basename of the shell’s terminal device name.
\nA newline.
\rA carriage return.
\sThe name of the shell, the basename of $0 (the portion following the final slash).
\tThe time, in 24-hour HH:MM:SS format.
\TThe time, in 12-hour HH:MM:SS format.
\@The time, in 12-hour am/pm format.
\AThe time, in 24-hour HH:MM format.
\uThe username of the current user.
\vThe version of Bash (e.g., 2.00).
\VThe release of Bash, version + patchlevel (e.g., 2.00.0).
\wThe current working directory, with $HOME abbreviated with a tilde (uses the $PROMPT_DIRTRIM variable).
\WThe basename of $PWD, with $HOME abbreviated with a tilde.
\!The history number of this command.
\#The command number of this command.
\$If the effective uid is 0, #, otherwise $.
\nnnThe character whose ASCII code is the octal value nnn.
\\A backslash.
\[Begin a sequence of non-printing characters. This could be used to embed a terminal control sequence into the prompt.
\]End a sequence of non-printing characters.
Bash Reference Manual
Reference Documentation for Bash
Edition 5.0, for Bash Version 5.0.
May 2019
Chapter 6.9 - Controlling the Prompt, Pages 97-98
Downloaded 19Sept2019

Related Articles:

How to Partition a Disk in Linux with fdisk


Leave a Reply

Your email address will not be published. Required fields are marked *