~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:
| Sequence | Description |
|---|---|
| \a | ASCII bell (beep) |
| \d | Date (e.g., "Mon May 26") |
| \h | Hostname (short) |
| \u | Username |
| \w | Full path of current dir |
| \W | Base name of current dir |
| \t | Time (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
| Sequence | Color |
|---|---|
| \033[0;31m | Red |
| \033[1;32m | Light green |
| \033[0;33m | Brown |
| \033[1;34m | Light blue |
Background Colors
| Sequence | Color |
|---|---|
| \033[0;41m | Red background |
| \033[0;42m | Green 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 Code | Action |
|---|---|
| \033[s | Save cursor position |
| \033[u | Restore cursor position |
| \033[0;0H | Move 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 PS1source ~/.bashrcConclusion
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