Thursday, April 02, 2009

*N*X: Shell Hack : Use a Different Color for the root Shell

Today's Lifehacker tells how to do it.


Lifehacker - Use a Different Color for the Root Shell Prompt - Terminal
Use a Different Color for the Root Shell Prompt
By The How-To Geek, 1:00 PM on Thu Apr 2 2009, 3,749 views (Edit post, Set to draft, Slurp)

Copy this whole post to another site
Slurp cancel
loading comment page

Linux only: Reader Chris writes in with an excellent tip that changes the prompt to red when using the root account from the terminal—as a reminder to be more careful.

Using the tip is relatively simple—just edit the /root/.bashrc file and add in the following, preferably commenting out the existing lines that set the color, though you can simply add this line to the end of the file.

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

Once you've added this line, anytime you switch to using the root shell you will see the prompt in red with white text for the command line. Chris takes it further, with a line that turns the prompt green for regular users, which you can enable by adding the following to your ~/.bashrc file:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

This tip can really come in handy if you have a bunch of terminal windows open at once, so you can tell at a glance which ones are using root mode and which aren't