There is no technical reason to change the color of the terminal console, but anyone can issue commands as another user or logged in to the wrong machine because all of the prompts look the same.
That is what we are going to define:
Find out what is your current prompt style code:
To change your prompt style issue the following command replacing the bold text with the desired style:
Try the following two styles to see how it works:
export PS1="\[$(tput setaf 3)\]\t \[email protected]\h:\w $ \[$(tput sgr0)\]" export PS1="\[$(tput setaf 1)\]\t \[email protected]\h:\W $ \[$(tput sgr0)\]"
Note the difference between the lines. Just one number changed: 3 to 1. It is because 3 means Yellow and 1 means Red.
Various color codes for the tput command
- 0 = Black
- 1 = Red
- 2 = Green
- 3 = Yellow
- 4 = Blue
- 5 = Magenta
- 6 = Cyan
- 7 = White
As soon as you exit the terminal this configuration will disappear. To make it permanent edit the file ~/.bashrc (for Ubuntu 20.04, for others can be: .bash_profile):
sudo nano ~/.bashrc
And append the defined color definition line at the end.
There are other ways to create more complex color schemes, such as changing the color of specific pieces of the prompt or applying Bold or Italic:
export PS1='\[\033[01;33m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
The syntax follows this structure \[\033[X;Y]m\].
Where the X is the attribute and Y is the color.
Most common attributes:
|0||Normal text (This is the default value even if no attribute is set)|
|1||In the Ubuntu Terminal, this value specifies bold text|
|5||For blinking text|
|7||Reverses text and background colors|
|8||For hidden text|