Bash Prompt -PS1

Some students in my SEC542 SANS class noted the funky Bash shell prompt I have for my terminal windows and wanted me to share it. So, this is a post to share it.

My Bash shell prompt is:

┌─[HH:MM:SS]─[hostname: PresentWorkingDirectory]
└──> $

and looks like this in the terminal when I took a pic of my system named “whisper” at 17:52:15 (5:52pm) and was in my home directory (~):

capture

I put these into the .bashrc file in my user accounts (and root’s account) on linux systems. There is usually a default value for the “PS1” variable that needs to be replaced with your custom content. Make sure to make a backup of your old .bashrc file in case something goes wrong and you need to revert.

My PS1 variable in my .bashrc file looks like this:

\n\[\033[0;35m\]\342\224\214\342\224\200$([[ $? != 0 ]] && echo "[\[\033[0;37m\]\342\234\227\[\033[0;35m\]]\342\224\200")[\[\033[0;33m\]\t\[\033[0;35m\]]\342\224\200[\[\033[0;37m\]\h : \[\033[0;32m\]\w\[\033[0;35m\]]\n\342\224\224\342\224\200\342\224\200> \[\033[0;37m\]$ \[\033[0m\]

There are a mix of escape sequences and variables in the prompt. Some are for drawing the angle brackets and such, some are for the colors and others pull system information about the current time, hostname and current directory. See http://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html for more info on those escape sequences.

One last thing, if it is run as a superuser (UID == 0), the prompt color will turn red to show that you have elevated privileges.

Interested in more information about customizing your Bash prompt?

Comments are closed.

A WordPress.com Website.

Up ↑

%d bloggers like this: