Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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
up vote 7 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)
    export PS1="\u@\[$bold\]\h\[$reset\]:\w \$ "

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)
  PS1='\[$red\]\u\[$reset\]@\[$green\]\h\[$reset\]:\[$blue\]\w\[$reset\]\$ '
share|improve this answer
works like a charm! – John Berryman Jul 6 '11 at 2:04

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

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:

PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '

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

I like the way Gentoo does it:

"\[\033[01;32m\]\u@\h\[\033[01;34m\] \W \$\[\033[00m\] "

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.