The terminal for running commands in Ubuntu and any other Linux distro is dull to look at, but you can easily spice it up a little with some colour.
Simply run the following command in a terminal:
gedit ~/.bashrc
When .bashrc opens, locate and uncomment “force_color_prompt=yes” (that is, remove the hash, so it no longer looks like: #force_color_prompt=yes).
Save the file, and open a new terminal window, and you should already see a change (the prompt should be Light Green, which is defined by 1;32). You can then change any colour value you like; eg: 0;35 = Purple.
To edit the colour values, locate the following section, and change the default values with some of the examples listed further down:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
You can check out this Bash colour chart for a full range of colour values, but here are a few basic ones you can play around with (note that “Light” isn’t what you might think – it actually means “bold”):
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
For those curious about the codes used in the example pic, here’s the line from that section:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
As you can see, 1;35 is the Light Purple user and machine name, while the 1;34 is the Light Blue tilde (~). If you want yours a bit brighter, try:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u@\h\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ '
… which will give you Light Cyan and Light Red, and look like the following:
In case you’re wondering about the colon and dollar sign, you can change those as well, but you need to do more than just edit the colour values. You’ll need to insert code in the appropriate places, so the line looks like this:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u@\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]\$ '
You’ll notice the first highlighted code is just before the colon (:) while the second is before the dollar sign ($). In this example, both are yellow, with the result looking like:
Now, if you want to go even further, you can make the user name stand out by doing the following:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u\[\033[01;35m\]@\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]\$ '
That extra bit of code is specifying Light Purple for the @ and the desktop name, making it now look like:
And of course, one last bit of fiddling and you can have every element a different colour. In this last example, we’re going to make the computer name the same as the user name, and have them broken up by red, as with the yellow elements:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u\[\033[01;31m\]@\[\033[01;36m\]\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]\$ '
As you can see, the @ is now Light Red, while the code before \h is specifying Light Cyan, like the user name:
You’ll also notice when you type commands that the colour of the text will match that of the $, which can be preferable if using a “light” colour, since the bold text is easier to see.
Lastly, in case you’re wondering whether the prompt can end in anything other than a $, the answer is yes, and it’s as easy as opening the Character Map (sudo apt-get install gucharmap if you don’t have it), selecting a character, and pasting it over the $ at the end of the line of code:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u\[\033[01;31m\]@\[\033[01;36m\]\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]ᛤ '
In that example, I simply selected a cool looking character from the font Runic, and replaced the $ with that. You’ll also note one other thing you’ll have to do, and that’s remove the \ before it, or else that will appear too (obviously, that doesn’t happen if using the $, but will with other characters).
Have fun experimenting!
☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻
Did this information make your day? Did it rescue you from hours of headache? Then please consider making a donation via PayPal, to buy me a donut, beer, or some fish’n’chips for my time and effort! Many thanks!
Thanks for the tips, colorful terminal make me enjoy to play with it. lol
thanks man great help …………
Thanks, that helped me a lot!!
Yes, I’ve noticed when you type commands that the colour of the text will match that of the $. But then, for commands like ls, the output continues in the color of the $. How to change back to default text color for the output of the command typed?
Thanks.
I just tried it on my system, and ls output is how it should be, with none of the colours matching the prompt. My prompt looks exactly like the very last example, with bold yellow on a dark background, and ls output is in white and pale blue, so I’m not sure what is happening your way, as I can’t recreate it. For other commands that spit out data, like du or running apt-get update, etc, the output will be the same as the prompt colour, which it always has been. But ls should be an exception, so if you find the answer, please post it here.
What I notice with ls or du is that the color of the output continues to be in the colour of the prompt. However, for ls, the output takes the default colors set by CLICOLOR and LSCOLORS after the first instance of a directory name appearing in the output which is set to a different color.
So, in the following code for a very colourful prompt, I know that if I add
\[\e[0m\] after the last $, it will terminate the overflow of the prompt color.
However that would also disable the color of the typed in command after the prompt. I was wondering if there is an option that can go between the $ and \[\e[0m\] to set the color of the command typed in.
function prompt
{
local GREEN=”\[33[0;32m\]”
local CYAN=”\[33[0;36m\]”
local BLUE=”\[33[0;34m\]”
local RED=”\[33[1;31m\]”
export PS1=”
\[\e]2;\u@\h\a\e[0;31m${GREEN}\u${CYAN}@${BLUE}\h ${CYAN}\w${RED}
$ ”
}
prompt
add this after the PS1 line
trap ‘echo -ne “\e[0m”‘ DEBUG
Hi
when you change the color and then you type su, the change done before do not take effect like superuser, how can I fix that ?
Thank you soooo much
hmmm, it doesn’t work!
That’s weird – you’re the only one I’ve ever heard of for whom it hasn’t worked! Follow the instructions again, and see if you did something wrong.
[…] https://ubuntugenius.wordpress.com/2011/07/11/how-to-change-the-command-line-prompt-colour-in-the-ubu… […]
Thank you :)
Many thanks!
Many Thanks…
[…] http://www.cyberciti.biz/tips/bash-a…inux-unix.html Neat bash aliases https://ubuntugenius.wordpress.com/20…inux-terminal/ Change console style http://leocharre.com/articles/settin…bash-terminal/ […]
[…] http://www.cyberciti.biz/tips/bash-a…inux-unix.html Neat bash aliases https://ubuntugenius.wordpress.com/20…inux-terminal/ Change console style http://leocharre.com/articles/settin…bash-terminal/ […]
[…] How to Change the Command-Line Prompt Colour in the Ubuntu/Linux Terminal […]
Hey I changed the $ symbol but now my prompt starts on top of it? Can you help me fix that? Thanks.
Hi. Without any further info, all I can suggest is that you check you did the code correctly, and if worse comes to worse, just change it back to what it was. But any of the example codes I have in the article should work the same on any machine.
[…] In case you’re wondering how to customise your terminal with colours and different characters for the prompt, check out this guide! […]
Thank you so much..The information was really useful..I was also able to change it using the graphical method
http://newpcgeek.blogspot.in/2015/06/learn-how-to-change-colour-of-your.html
[…] Source: https://ubuntugenius.wordpress.com/2011/07/11/how-to-change-the-command-line-prompt-colour-in-the-ubu… […]
[…] How to Change the Command-Line Prompt Colour in the Ubuntu … – Jul 11, 2011 · The terminal for running commands in Ubuntu and any other Linux distro is dull to look at, but you can easily spice it up a little with some colour. […]
[…] المصدر ubuntugenius […]
[…] https://ubuntugenius.wordpress.com/2011/07/11/how-to-change-the-command-line-prompt-colour-in-the-ub… […]