When the installation completes a Linux system, the default terminal is generally black and white, how to turn the prompt into color, which needs to be configured in the $HOME/.BASHRC file by the modification of the PS1. Here is a detailed description.
Note: This article is a reference to Http://wsunwind.blog.sohu.com/192388839.html's related instructions
1 Simple Comprehension PS1
Modify the PS1 variable directly in the termial to change the prompt of the current environment, select the one you like to write into the. bashrc file.
For example, by adding the ps1= "This is my terminal:>" to the. BASHRC, your prompt will become
Note: There are no spaces behind PS1.
Sometimes we want to prompt character to display the current directory, host name, and so on useful information, then we need to use the backslash escaped character sequence, as follows:
\u User Name
\h hostname The first part
\h Hostname Full Name
\w current working directory (e.g. "/home/username/mywork")
\w "base name (basename)" For the current working directory (such as "mywork")
\ t 24-hour system time
\ t 12-hour system time
\@ 12-hour time with AM/PM
\d "Sat Dec 18″ format Date
\s the name of the shell (such as "bash")
\v bash version (e.g. 2.04)
\v Bash version (including patch level)
\ n line break
\ r return character
\ \ counter Slash
\a ASCII Bell character (you can also type 07)
\e ASCII Escape character (you can also type 33)
\[This sequence should appear before the character sequence that does not move the cursor (such as the color escape sequence). It enables bash to correctly calculate the wrapping.
\] This sequence should appear after the nonprinting character sequence.
Knowing all the escape sequences, you can customize your own terminal prompt.
For example, I want to display the current directory and host name to the prompt, only need to change the PS1 to "\[email protected]\h:\w>", the effect is as follows
2 Color Configuration
After we have designed the prompt, we can add color to them and add a color that adds a private escape sequence that the terminal (rather than bash) recognizes, so that it displays portions of the text in color. Standard Linux terminals and X terminals allow you to set the foreground (text) color and background color and, if necessary, enable the "bold" character. There are eight colors that we can choose from (in numbers).
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
Code meaning
————————-
0 OFF
1 highlighting
4 Underline
5 flashes #闪烁这个选项在我机子上没反应, so there's no verification, don't know if it can ha
7 Anti-white display
8 Not visible
Now we can define a color prompt!
Format:\[\e[1;2m\] ...
1 is the foreground color, 2 is the back color or the code (highlighting, flashing, and so on, the default foreground color is the system default), ... The content to be added by the user.
When all settings are complete, add \[\e[0m\] If you want the user to enter a command that is not affected by the color.
For example: ps1= "\[\e[36;1m\]\[email protected]\h:\[\e[31;1m\]\w\[\e[34;1m\]> \[\e[0m\]", this setting is all Word Fugauliang, the user host part is set to blue, The directory is set to red,> blue, the effect is as follows
However, when we write this configuration to the. bashrc file, we will find a problem, that is, Terminal's title bar has become an immutable "termianl", which may not be what we want, the default display user name, host name and current working path (I prefer this A default ha), we may wish to bring him back. In fact, the configuration title bar and the above mentioned configuration prompt content is similar, just to add:
\e]2;...\a
... Enter content for the user
Configuration of the terminal prompt