OS: Linux
You should be familiar with Bash prompt if you are a linux user. Whenever you start a terminal the command line interface of the Linux server you should be using Bash as a default unless you have change the default shell to something else.
Bash prompt is set by the environment variable PS1 (Prompt String 1). The variable is configure by default using the settings in /etc/.bashrc , you should be changing the user prompt in the user directory if you want to change the prompt that the user will see. /home/<user>/.bashrc
The file should be hidden by default. So you might want to use ls -a to see the file.
To see the current PS1 value you can use the command echo $PS1. Here is a sample output of the prompt in Debian.
To change the prompt temporally you can use the following command. PS1=”<Enter the Values>”
It is useful if you are writing a blog like me or doing a video and you want to highlight certain key attributes or differentiate users or system.
Here are a list of common values.
Values | Description |
\u | Username |
\h | Short hostname |
\W | Basename of the current working directory ~ for home or root |
\s | Shell name (base or sh) |
\v | The shell’s version |
\w | The whole path of the directory (Similar to pwd command) |
\d | Date |
\D{format} | Custom date |
\D{%c} | The date and time in the current locale |
\n | New line |
\! | History number |
Using the color values. \e[
Values | Description |
\e[ | Is an escape character. What follow is the values to change the colors. Start color scheme |
\e[m | End the color scheme |
x;y | Color pair. x determine the brightness. To make red brighter you can start with 0 or even -1 y is the color eg. 30 is black. |
30 | Black |
31 | Red |
32 | Green |
33 | Brown |
34 | Blue |
35 | Purple |
36 | Cyan |
37 | White |
38 | Orange |
39 | Yellow |
Example of Black and Blue