Linux Modify shell command prompt and color
1. Load the configuration file sequence during the Linux login process:
/ETC/PROFILE→/ETC/PROFILE.D/*.SH→~/.BASH_PROFILE→~/.BASHRC→[/ETC/BASHRC]
You can view the default ~/.BASHRC file as follows:
[Root@~/wade/codereview/redis-2.8.17]cat ~/. BASHRC # User specific aliases and Functions # Source Global Definitionsif [-f /etc/BASHRC ]; then. /etc/bashrcfi
2. shell command prompt and color is configured by PS1:
[Root@/etc/init.d$PS 1[\[\e[32;40m\]\u@\w]
The parameters commonly used in 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 \#: #下达的第几个命令 \$: # Prompt character, if root, the prompt is: #, the average user is: $
3. Color value setting: The format of 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 B30 black, red, green, yellow, blue, Purple 36 Green Blue Panax Notoginseng 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]$ '
4. Take the author's ~/.BASHRC configuration as an example:
[Root@~]# Cat ~/.BASHRC#. BASHRC# User specific aliases and Functionsexport ps1= "[\[\e[32;40m\ ]\[email protected]\w]\$ ' # Source Global Definitionsif [-f /etc/BASHRC ]; then. /etc/bashrcfi
5. After the modification is completed, reload the next ~/.BASHRC to take effect:
Linux Modify shell command prompt and color