Customize the root shell's prompt in Terminal

19.02.2010
Today's hint is for those of you who, like me, use Terminal often and occasionally have a need to do things there as the root user. If you don't know what Terminal is, don't know what the root user is, or haven't ever heard of the sudo command, this hint probably isn't for you.

In Terminal, you enter root mode with the sudo command; in particular, if you've got a lot to do as root, it's easiest to open a root shell with sudo -s. You then stay in root mode until you type exit, whereupon you revert to your "normal" admin-level powers.

There's just one problem with this, though--the default root command prompt isn't nearly scary enough to remind you of the power you're wielding while in this mode.

When running in root mode, the default prompt of bash-3.2# looks too much like the standard prompt for my tastes--I want something that really reminds me of what I'm doing, to hopefully prevent me from doing something really stupid while operating as root.

If you'd like to change your root prompt, assuming you're using the default bash shell, here's how to do it. Using nano or vi or BBEdit or whatever your favorite pure text editor may be, edit the file named .profile in your user's home directory.

(If this file doesn't exist, create it. There's also a slim chance you may have a file named .bash_profile instead; if you do, edit that file and not .profile.)