Custom CLI Bash Prompt Colors

Some quick notes for me on how I customize my shell when I set up my servers. This is pretty much the layout I use for all users:

# /etc/bashrc (PS1)

[\[\e[0;36m\]\t\[\e[0m\]] [\[\e[31;1m\]\u\[\e[0m\]@\h \W]\\$


[07:58:50] [root@athena ~]#

# /etc/bashrc (PS1)

[\[\e[0;36m\]\t\[\e[0m\]] \[[\e[33;1m\]\u\[\e[0m\]@\h \W]\\$


[08:04:38] [root@theia ~]#

Available Colors (Courtesy of TLDP.Org)

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
Reset         0m

Additional Notes: Russell has reminded me that you can typically export the PS1 value while logged in as the user.

some@server$ export PS1="[\[\e[0;36m\]\t\[\e[0m\]] [\[\e[31;1m\]\u\[\e[0m\]@\h \W]\\$"

While this can be useful at times, I find that it doesn't usually "save" this and after logging out and back in, the prompt returns to how it previously was. If you want to change the prompt for a single user, use this method and also add the "PS1='xxxxx'" line to the /home/user*/.bash_profile file. Adding these settings (or similar) to the /etc/bashrc file will make the changes globally for all users, which I personally find more appealing.

You may also like...

2 Responses

  1. Awesome, it works for me, plain white makes it hard to distinguish what's what most of the time. Also, be sure to add PS1= to the beginning of the color code. You can also export the PS1 variable to make the changes occur immediately:

    some@server$ export PS1= "[\[\e[0;36m\]\t\[\e[0m\]] [\[\e[31;1m\]\u\[\e[0m\]@\h \W]\\$"

    • David says:

      The only issue I've had with using export was that it wouldn't actually save it. Logging out and back in of the user it was exported to causes it to revert back (CentOS 5 does this anyways).

      Changing it using /etc/bashrc makes it system-wide for all users and not user-specific.

Leave a Reply

Your email address will not be published. Required fields are marked *