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.
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 |
ps1_old="$PS1"
PS1="\$ "
PS1="
\[\a\]
\$ "
PS1="\A \h \$ "
17:33 linuxbox $
PS1="$ps1_old"
Sequence | Color |
---|---|
\033[0;31m | Red |
\033[1;32m | Light green |
\033[0;33m | Brown |
\033[1;34m | Light blue |
Sequence | Color |
---|---|
\033[0;41m | Red background |
\033[0;42m | Green background |
PS1="
\[\033[0;31m\]
<\u@\h \W>\$
\[\033[0m\]
"
PS1="
\[\033[0;41m\]
<\u@\h \W>\$
\[\033[0m\]
"
Escape Code | Action |
---|---|
\033[s | Save cursor position |
\033[u | Restore cursor position |
\033[0;0H | Move to top-left corner |
PS1="
\[\033[s\033[0;0H\033[0;41m\033[K\033[1;33m\t\033[0m\033[u\]
<\u@\h \W>\$ "
# Custom prompt with red bar and yellow clock
PS1="..."
export PS1
source ~/.bashrc
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.