Linux terminal Everyone must know, recently in the use of the time to find a folder in the deep level of the directory, the absolute path of the terminal hint is very long, so that people feel very unaccustomed, here to introduce how to modify the terminal tips, by the way, introduce the following prompt color:
Introduction to PS1 Variables
PS1 is an environment variable for Linux end users that describes the settings for the command line prompt.
You can use the Man Bash command to view the Bash Handbook, find the special characters that the variable supports, and the meaning of these special characters:
\d: #代表日期, formatted as weekday month date, for example: "Mon-1"
\h: #完整的主机名称.
\h: #仅取主机的第一个名字, as in the example above, Fc4,.linux is omitted
\ t: #显示时间为24小时格式, such as: HH:MM:SS
\ t: #显示时间为12小时格式
\a: #显示时间为24小时格式: hh:mm
\u: #当前用户的账号名称
\v: #BASH的版本信息
\w: #完整的工作目录名称. Home directory will be replaced by ~
\w: #利用basename取得工作目录名称, so only the last directory is listed
\#: #下达的第几个命令
\$: #提示字符, if it is root, the prompt is: #, the average user is: $
The above is just the preparation of knowledge ... Official Entry topic:
To modify a terminal prompt:
To view the default prompt settings
$ echo $PS 1
It should show: \[\e]0;\[email protected]\h:\w\a\]${debian_chroot:+ ($debian _chroot)}\[email protected]\h:\w\$
Modify the default settings, add the following command to the current logged in user's ~/.BASHRC file, and then use the source to make it effective, if you do not understand the role of ~/.BASHRC file, you can refer to my article describes:. Bash_profile. BASHRC The order of execution of the profile file's function
$ VI~/.BASHRC
#在文件最后添加如下设置
Export ps1= "[\[email protected]\h \w] \$"//note here is just a format, specifically what the meaning of each section looks below:
$ source ~/.BASHRC//make its settings effective
Color settings
The format for setting the character sequence color in PS1 is: [\e[f; BM]
where "F" is the font color, number 30~37; " B "For background color, number 40~47.
Below is a look at the color table:
Foreground background color
------------------------
30 40 Black
31 41 Red
32 42 Green
33 43 Yellow
34 44 Blue
35 45 Purplish red
36 46 Cyan Blue
37 47 White
Effect Control Code:
Code meaning
-------------------------
0 OFF
1 highlighting
4 Underline
5 Flashing
7 Anti-white display
8 Not visible
Modify the prompt color sample
$ ps1= "\[\e[32m\]#\##\[\e[1;31m\]\[email protected]\[\e[36m\]\h \w]\$\[\e[m\]"//correspond to know what each part means. Note that there are some blanks in the wrong
Description
1, ' \[\e[32m\] ' is used to set the color of ' #\## ' to green, #\# #就是显示现在运行的是第几条命令
2, ' \[\e[31m\] ' set ' \[email protected] ' color is red and highlighted, if you specify multiple numbers need to be separated by semicolons. \[email protected] is the currently logged in user name followed by an ' @ ' symbol.
3, ' \[\e[36m\] ' set ' \h\w ' is cyan Blue, \h represents the first host name, if the host name is centos6.lampbo.org, then the display centos6;\w will show the full absolute path.
4, ' \$ ' prompt character, if it is root, the prompt is: #, the average user is: $.
5, ' \[\e[m\] ' is used to turn off color settings. If you do not have this, then your command prompt, including what you output through the command prompt, is the same as the last color setting.
6, in order to be able to start and login can keep the variables just set, need to add PS1 settings to the user home directory of the. bashrc file.
Following the above example setup is Jiangzi:
Ubuntu system modify terminal prompt and set color highlighting