Modify Linux terminal command line colors
1.ps1
To modify the Linux terminal command line color, we need to use the PS1,PS1 is an environment variable for Linux end users to describe the command line prompt settings. In the terminal input command: #set, you can find the definition of PS1 in the output as follows:
Ps1= ' [\[email protected]\h \w]\$ '
The meanings of the commonly used parameters in the definition of PS1 are as follows:
\d:#代表日期, formatted as weekday month date, for example: "Mon-1"
\h:#完整的主机名称
\h:#仅取主机的第一个名字
\ t:#显示时间为24小时格式, such as: HH:MM:SS
\ t:#显示时间为12小时格式
\a:#显示时间为24小时格式: hh:mm
\u:#当前用户的账号名称
\v:#BASH的版本信息
\w:#完整的工作目录名称
\w:#利用basename取得工作目录名称, so only the last directory is listed
\#: #下达的第几个命令
\$:#提示字符, if it is root, the prompt is: #, the average user is: $
From this, we know that the Linux default command line prompt message is: [Current user's account name @ host's first name working directory last item]#
2. Setting the Color
The format for setting the character color in PS1 is: \[\e[f; Bm\], where "F" is the font color, number is 30-37, "B" is the background color, number 40-47. The color table is as follows:
F B
30 40 Black
31 41 Red
32 42 Green
43xxx
34 44 Blue
35 45 Purplish red
36 46 Cyan Blue
37 47 White
Depending on the color table, the color of the Linux Terminal command line can be personalized by applying the character color formatting. For example, to set the command line format for the green Word black, display the current user's account name, the first name of the host, the full current working directory name, 24-hour format time, you can use the following command:
#PS1 = ' [\[\e[32;40m\]\[email protected]\h \w \t]$ '
3. Modify the. bashrc file
The above settings can only change the command line format of the current terminal, close the terminal, in a reopened terminal in the command line format will revert to the default form. To permanently change the terminal command line format, you need to modify the. bashrc file.
Use command: #cd/
#ls-L-A
You can see the. bashrc this file. Using commands
#gedit. BASHRC
Include in the. bashrc file
Ps1= ' [\[\e[32;40m\]\[email protected]\h \w \t]$ '
This statement, and then save, can permanently change the terminal command line format.
Modify the Linux environment variable to change the terminal command line color and style