Highlight Your Shell Prompt When Working as Root
A useful thing that some distros have started doing is setting the color of your shell prompt differently if you're logged in as root. This gives you an additional visual cue that helps avoid doing things as root when you don't want to. If your distro doesn't do this for you, you can accomplish it by changing your .bashrc files. To set the color of your shell prompt you set the shell variable PS1.
To make the prompt red when you're running as root add this to /root/.bashrc:
PS1="\[\e[31m\]\h:\w#\[\e[m\] "
To make the prompt green when running as a normal user add this to ~/.bashrc:
PS1="\[\e[32m\]\u@\h:\w\$\[\e[m\] "
See the shell man page and search the web for ANSI Escape codes for more info on the meaning of the escape sequences.
In the image below the top shell window is a normal user, the bottom one is a root window.
Related Articles
- Safely Running Programs as root by Phil Hughes
- Extending the Bash Prompt by Giles Orr
- Best of Technical Support by LJ Staff
Mitch Frazier is an Associate Editor for Linux Journal.
Trending Topics
| The Linux powered LAN Gaming House | Feb 08, 2012 |
| Creating a vDSO: the Colonel's Other Chicken | Feb 06, 2012 |
| Your CMS Is Not Your Web Site | Feb 01, 2012 |
| Casper, the Friendly (and Persistent) Ghost | Jan 31, 2012 |
| Razor-qt 0.4 - Qt based Desktop Environment | Jan 30, 2012 |
| Using Plop Boot Manager for USB Boot | Jan 25, 2012 |
- Readers' Choice Awards 2011
- Creating a vDSO: the Colonel's Other Chicken
- Validate an E-Mail Address with PHP, the Right Way
- Boot with GRUB
- Why Python?
- The Linux powered LAN Gaming House
- Python for Android
- Bash Regular Expressions
- Casper, the Friendly (and Persistent) Ghost
- Monitoring Hard Disks with SMART
- KDE Bloat
1 hour 40 min ago - My C-64 Memories
2 hours 26 min ago - Spam
3 hours 34 min ago - Ooops....
8 hours 25 min ago - ----- http://ai.vc/zd
18 hours 21 min ago - ----- http://ai.vc/zd
18 hours 22 min ago - ----- http://ai.vc/zd
18 hours 22 min ago - ----- http://ai.vc/zd
18 hours 23 min ago - Best online store
18 hours 25 min ago - ----- http://ai.vc/zd
18 hours 25 min ago





Comments
Thanks
Thanks for this useful information.