Customize the root shell's prompt in Terminal

19.02.2010

* [\u] \w \$ - the user name in brackets, followed by the directory and the # symbol

* \[\e[0m\] - another non-printing sequence; this one sets the colors back to the defaults, so only the prompt is yellow-on-red

You can learn a bit more about prompts by reading the bash manual (type man bash in Terminal). Search (by typing a forward slash, /) for When executing interactively to jump directly to the section on prompting. Even that, though, won't help explain most of the above. For that, you'll need some . In particular, I like for its good overview, and for its coverage of color usage.

If this hint inspires you to change your default non-sudo prompt, you can do that, too. Add another line to the .profile file which begins export PS1="..., and then build the prompt string as you wish.

If you mess something up and wind up with an unreadable prompt (What? No, that's never happened to me!), just remove the line from the .profile file, save your changes, and open a new Terminal window. I will caution you, though, that playing with prompt strings can be an amazingly time-consuming diversion..."just one more little change!"