How to customize and change colour of the bash login prompt in Linux Here, I will explain two methods that we can use to customize and change the colour of the login prompt of our bash shell in Linux.
1. Octal Method
2. Bash Method
Before that, let's take a look at the different colour code that we are going to use here:
Black -> 30
Red -> 31
Green -> 32
Yellow -> 33
Blue -> 34
Magenta -> 35
Cyan -> 36
White -> 37
Bright Black -> 90
Bright Red -> 91
Bright Green -> 92
Bright Yellow -> 93
Bright Blue -> 94
Bright Magenta -> 95
Bright Cyan -> 96
Bright White -> 97
The following additional prompt must be added additionally to each method:
start -> \[
end -> \]
1. Using Octal FormatThe starting and ending of the command should be like this:
start -> \033[0m
end -> \033[m
Now, to Change the color of the prompt to 'RED':
# export PS1='\[\033[31m\][\u@\h ~]# \[\033[m\]'
For Example, Here is my login prompt:
Now, after changing the colour to RED:
Below image shows the complete list of color codes:
Similarly, you can modify the command to change the prompt to different colors, you only need to care about below format while using the above command:
start -> \[\033[31m\] <-- Here modify '31m' with the color number
end -> \[\033[m\] <-- to reset the terminal or else your commands would also appear with the same color
2. Using Bash FormatThe starting and ending of the command should be like this:
start -> \e
end -> \e[m
Now, to Change the color of the prompt to 'RED':
export PS1='\[\e[31m\][\u@\h]#\[\e[m\] '
For Example, Here is my login prompt:
Now, after changing the colour to RED:
Similarly, you can modify the command to change the prompt to different colors, you only need to care about below format while using the above command:
start -> \[\e[33m\] <-- Here modify '31m' with the color number
end -> \[\e[m\] <-- to reset the terminal or else your commands would also appear with the same color
I hope the article was interesting
!!