~2 min read • Updated Jul 15, 2025

The shell prompt is an often overlooked but highly customizable feature of the Linux terminal. Defined by the PS1 variable in bash, the prompt shows useful info like username, hostname, and current directory. By editing PS1, users can display dynamic elements, include colors, and even add a clock — blending both style and utility.


Prompt Anatomy


A typical bash prompt might look like:


[me@linuxbox ~]$

Defined by:


echo $PS1

[\u@\h \W]\$

It uses escape sequences interpreted by bash:


SequenceDescription
\aASCII bell (beep)
\dDate (e.g., "Mon May 26")
\hHostname (short)
\uUsername
\wFull path of current dir
\WBase name of current dir
\tTime (HH:MM:SS)
\@Time (AM/PM format)
\!Command history number
\$Prompt character ($ or #)
\[Start non-printing characters
\] End non-printing characters

Experimenting with Prompt Designs


Back Up the Original


ps1_old="$PS1"

Minimal Prompt


PS1="\$ "

Add a Bell


PS1="

\[\a\]

\$ "

Informative Prompt (Time + Hostname)


PS1="\A \h \$ "

17:33 linuxbox $

Restore Original


PS1="$ps1_old"

Adding Color to the Prompt


Text Colors


SequenceColor
\033[0;31mRed
\033[1;32mLight green
\033[0;33mBrown
\033[1;34mLight blue

Background Colors


SequenceColor
\033[0;41mRed background
\033[0;42mGreen background

Example: Red Text Prompt


PS1="

\[\033[0;31m\]

<\u@\h \W>\$

\[\033[0m\]

 "

Example: Red Background


PS1="

\[\033[0;41m\]

<\u@\h \W>\$

\[\033[0m\]

 "

Cursor Control


Escape CodeAction
\033[sSave cursor position
\033[uRestore cursor position
\033[0;0HMove to top-left corner

Top Bar with Clock


PS1="

\[\033[s\033[0;0H\033[0;41m\033[K\033[1;33m\t\033[0m\033[u\]

<\u@\h \W>\$ "

Save Prompt Permanently


# Custom prompt with red bar and yellow clock
PS1="..."
export PS1

source ~/.bashrc

Conclusion


Customizing the shell prompt with PS1 lets users enhance both appearance and utility. With escape sequences for text, color, and cursor control, the terminal becomes more intuitive and personalized. Experimenting with these options improves the user experience and deepens command-line mastery.


Written & researched by Dr. Shahin Siami