Changing your BASH prompt
Your BASH prompt is defined by the $PS1 environment variable. You can view the current setting by running the following command:
echo $PS1
This will ouput a string such as:
\\u@\\h:\\w\\$
Here is a list of the most commonly used escape characters:
\\h the hostname up to the first `.'
\\H the hostname
\\s the name of the shell, the basename of $0
(the portion following the final slash)
\\u the username of the current user
\\w the current working directory
\\W the basename of the current working directory
\\! the history number of this command
\\$ if the effective UID is 0, a #, otherwise a $
(Please check the BASH man page for the complete list)
To set a new prompt string you can just export a new value of $PS1 using the following command:
export PS1="\\u@\\h:\\w\\$ "
To make this permanent you will need to add the above command to a global startup file or your ~/.bashrc
To use colours in your prompt you will need to use the following escape sequence:
\\033[1;31m\\]
This will set all proceeding text to light red. You will need to use a similar escape sequence to set the colour back otherwise all your terminal text will be in light read,like so:
\\033[0m\\]
Here is a the list of available colours:
Black 0;30 Dark Gray 1;30
Blue 0;34 Light Blue 1;34
Green 0;32 Light Green 1;32
Cyan 0;36 Light Cyan 1;36
Red 0;31 Light Red 1;31
Purple 0;35 Light Purple 1;35
Brown 0;33 Yellow 1;33
Light Gray 0;37 White 1;37
So a final example of a prompt string is:
export PS1="\\033[1;31m\\]\\u@\\h:\\w\\$\\033[0m\\] "
which would give you a prompt of:
user@host:/tmp$
With a red "$"
Last updated: 25/06/2005