•  
  • Archives for October 22, 2010 (1)

Useful coloured command prompt for Linux

Categories: InfoTech
Tags: No Tags
Comments: No Comments
Published on: October 22, 2010

I find it useful to have a visual prompt when I am logged into a Linux server as root (something you should rarely do).  One way of doing this is by adding colour to your command line prompt.  I decided to colour the username green if logged in as a regular user, and red if logged in as root.

It looks like this:

[username@hostname ~]$ 

and when logged in as root:

[root@hostname ~]# 

Here’s how to do it.  While logged in as yourself, edit your .bashrc file and change the export PS1 line so it reads like this:

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

Now su to root, and edit it’s .bashrc file changing export PS1 to this:

export PS1='[[e[0;31m]u[e[m]@h W]$ '

That easy.  You can do a lot more things with your command prompt, but this is enough for me.  Be careful when using non-printing characters (such as the colour commands above).  These should be surrounded by escape block ([ and ]).

page 1 of 1
Latest Tweet

dunxd: Melon time

(Updated 17 days, 15 hours, 1 minutes ago)

Photos
Duncan Drury's photo Duncan Drury's photo Duncan Drury's photo Duncan Drury's photo
Follow Me
DeliciousFacebookLinkedInTwitterYoutube
 
October 2010
M T W T F S S
« Sep   Dec »
 123
45678910
11121314151617
18192021222324
25262728293031