By using the
export PS1 command you can alter the way the bash prompt looks. You can do this right at the command line which will change it just for that session or you can place the config in your
.bashrc which loads every time you login to your bash shell. To reload your
.bashrc contents either start a new shell by doing
bash or logout and login again.
The first part defines colors. This is optional but makes it easier to create a pretty prompt. The
export PS1 command at the end is what is actually changing the prompt. The backslash codes that can be used are:
\udisplay the current username
\hdisplay the hostname of the system
\wdisplay the working directory
\ddisplay the date
\eASCII escape character
\tthe current time in 24-hour HH:MM:SS format
\Tthe current time in 12-hour HH:MM:SS format
\@the current time in 12-hour am/pm format
\Athe current time in 24-hour HH:MM format
\!the history number of this command
\#the command number of this command
\[begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\]end a sequence of non-printing characters
With color codes already defined
These examples assume the color codes at the top of this page have been added to the
export PS1="\[$bldgrn\]\[email protected]\h\w$ \[$txtrst\]"
Without color codes defined
It’s not necessary to add the color codes. These examples show how to use inline color codes to achieve the same results.
export PS1="\e[1;32m\[email protected]\h\w$ \e[0m"
export PS1="\e[1;32m\u\e[[email protected]\e[1;31m\h\e[0m\w$"