Recently , I was learning sed. The linux terminal is often all white, and the commands and output are difficult to identify. I found that it can be achieved by defining the PS1 environment variable.
1. Understand PS1
PS1 is the parameter used to define the command line prompt.
Query the defined value of the current PS1:
set | grip PS1 PS1 = '[\ u @ \ h \ W] \ $'
The following are the commonly used parameters and meanings of PS1 collected from the Internet:
\d : represents date, the format is weekday month date, for example: "Mon Aug 1"
\H : full hostname
\h : take only the first name in the hostname
\t : Display time in 24-hour format, such as: HH:MM:SS
\T : Display time in 12-hour format
\A : Display time as 24 hours format: HH:MM
\u : the account name of the current user
\v : BASH version information
\w : full working directory name
\W : Use basename to get the working directory name, only the last directory name is displayed
# : the first few commands issued
\$ : Prompt character, if it is a root user, the prompt is # , for ordinary users it is $
At this point, it can be seen that PS1='[\u@\h \W]\$ ' means: [the current user's account name @ the first name of the host name and the last layer of the directory name of the working directory]
2. Color settings
The format for setting the color is: start with [\e[F;Bm] and end with \e[m. Where "F" is the font color, numbered 30-37, and "B" is the background color, numbered 40-47.
FB Color
30 40 Black
31 41 Red
32 42 Green
33 43 Yellow
34 44 Blue
35 45 Fuchsia
36 46 Turquoise
37 47 White
Just put the color we need into the format, for example:
# PS1 = '[\ [\ e [32; 40m \] \ u @ \ h \ w \ t] $'
Displays the current user's account name (\u), the first name of the host (\h), the full current working directory name (\w), and the time in 24-hour format (\t)
Attaching my own format:
PS1='\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[35;40m\]\ W\[\e[0m\]]\$ '
3. Keep it forever
Modify the .bashrc file
Find the .bashrc file under the root user, edit the file, and add your favorite style to the last line, such as adding the above
PS1='\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[35;40m\]\ W\[\e[0m\]]\$ '
save and exit, then execute
source .bashrcThis will make it permanent