This post will guide you how to change the color of Bash shell prompt in Linux operating system. How do I customize the shell prompt in Linux. How to change the color of your bash prompt in your Linux system. How to customize bash colors in Linux terminal prompt.
Change Bash Prompt Color
If you want to change bash shell prompt in Linux terminal, you need to change the shell variable called PS1.
Check current Bash Prompt
You can use echo command to display the current value of PS variable, type:
#echo $PS1
Outputs:
[root@osetc_x8664 ~]# echo $PS1 [\u@\h \W]\$
So if you want to set bash prompt color, you can set the value of shell variable PS1 to a new value, type:
#export PS1="\e[0;35m[\u@\h \W]\$ \e[m"
Outputs:
[root@osetc_x8664 ~]# echo $PS1 [\u@\h \W]\$ [root@osetc_x8664 ~]# export PS1="\e[0;35m[\u@\h \W]\$ \e[m" [root@osetc_x8664 ~]$ [root@osetc_x8664 ~]$
Where,
- \e[ : specify the beginning of a color prompt
- 0;35m: set the color codes
- \u: display the username
- \n: display the hostname
- \W: display the current working directory
- \e[m: set the end of color prompt
The basic codes to change color of the foreground text are here:
30: Black 31: Red 32: Green 33: Yellow 34: Blue 35: Purple 36: Cyan 37: White
Making your Prompt Changes Permanent
If you want to the changes of your prompt permanently, you can export the PS1 variable in .bash_profle or .bashrc file. Jusing edit those files via vim editor:
#vim ~/.bashrc
then append the following line into it:
export PS1="\e[0;35m[\u@\h \W]\$"