Take the 2-minute tour ×

Possible Duplicate:
How to customize .bashrc to configure command prompt?

When I run a command, I often times have trouble finding the beginning of the command output. An easy fix to this would be to color or bold the command prompt so that I can easily see where I left off. How?

share|improve this question

marked as duplicate by Gilles, Caleb, Michael Mrozek Jul 6 '11 at 15:42


In Ubuntu (and possibly Debian too,) uncomment the force_color_prompt=yes in .bashrc, or run the terminal with TERM=xterm-color. –  alex Jul 6 '11 at 7:13
add comment

5 Answers

up vote 4 down vote accepted

Here's what I do. I use tput(1) instead of additional escape statements, because escape statements are hard for humans to read.

This is from my .bashrc

    ### Set the prompt like "username@hostname:~ $"
    # See: http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/
    # And: http://mywiki.wooledge.org/BashFAQ/037
    # 'tput bold' will work regardless of the foreground and background colors.
    # Place the tput output into variables, so they are only execd once.
    bold=$(tput bold)
    reset=$(tput sgr0)

Here's another alternative. This is much more readable then escape sequences.

  # Bash
  red=$(tput setaf 1)
  green=$(tput setaf 2)
  blue=$(tput setaf 4)
  reset=$(tput sgr0)
share|improve this answer
works like a charm! –  John Berryman Jul 6 '11 at 2:04
add comment

Here's mine from my .bashrc:

case $HOSTNAME in
    plato*) PSC="\e[1;33m" ;;
    *) PSC="\e[36m" ;;

PS1="[\j]\[${PSC}\]\u@\h(\l) \[\e[37m\][ \w ]\[\e[00m\]\n\[\e[1m\]\#\[\e[0m\] \$ "

Edit to taste. This one also uses a different color for my main workstation vs. other hosts.

share|improve this answer
add comment

There is an excellent reference page describing how to colourize your bash prompt on the Arch Linux wiki.

It includes information about the colours, escape sequences and the correct way to include other characters or to print information in the prompt, such as the directory, host, etc.

As an example, a simple prompt like:


Can be broken down into these elements:

\[\e[1;32m] - an opening square bracket printed in green (1;32m)

[\u@h \W] - username@hostname and the basename of the current working directory

\$ - the prompt (a # if the UID is 0)

\[e[0m\] - the text reset escape signalling the end of the colour sequence.

Using these sequences, you can build up a colourful, informative prompt.

A word of caution: if you fail to correctly escape sequences, you can wreak havoc with your terminal's ability to print text.

share|improve this answer
add comment

I like the way Gentoo does it:


Just add it to ~/.bashrc like so:

echo 'export PS1="\[\033[01;32m\]\u@\h\[\033[01;34m\] \W \$\[\033[00m\] "' | tee -a ~/.bashrc

You can then log out of your terminal/console or just source ~/.bashrc

share|improve this answer
add comment

For ease of use, you can first map your colors in your .bashrc and then reuse it in your prompt variable ($PS1):

Step 1.: Map the colors:


# Color mapping

Step 2. Re-define your PS1 variable:

PS1="$yellow[$CYAN\t$yellow][$red\H$yellow][$GREEN\w$grey$yellow]$NC# "
share|improve this answer
add comment
