1, first in the terminal with Gedit open configuration file (~/.BASHRC), such as:
$ gedit ~/.BASHRC
2. Add the following code at the end:
ps1=‘${debian_chroot:+ ($debian _chroot)}\[\033[01; 35; 40m\]\u\[\033[00; 00; 40m\]@\[\033[01; 35; 40m\]\h\[\033[00; 31; 40m\]:\[\033[00; 00; 40m\]\w \[\033[01; 32; 40m\]\$ \[\033[01; 36; 40m\] '
Some parameters:
\a ASCII Bell character (you can also type \007)
\d Date "Wed Sep" format
\e ASCII Escape character (you can also type \033)
\h the first part of the hostname (such as "Mybox")
\h Full name of the host (e.g. "mybox.mydomain.com")
\j number of processes suspended in this shell by pressing ^z
\l the terminal name of this shell (e.g. "TTYP4")
\ n line Break
\ r Carriage return character
\s The name of the shell (such as "Bash")
\ t -hour time (e.g. "23:01:01")
\ t time (e.g. "11:01:01")
\@ The time of the hour with am/pm
\u User name
\v bash version (e.g. 2.04)
\v Bash version (including patch level) ?/td>;
\w current working directory (e.g. "/home/drobbins")
\w base name (basename) for the current working directory (such as "Drobbins")
\! position of the current command in the history buffer
\# command number (as long as you type, it will accumulate at each prompt)
\$ If you are not superuser (root), insert a "$"; If you are a superuser, display a "#"
\xxx Insert an ASCII character represented by a three-digit xxx(with 0 instead of unused digits, such as "/007")
\\ back Slash
\[ 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.
Color =\033[code; foreground; background M
033[1;32;40m means that the highlighted font is green and the background color is black
If you specify a color for a parameter, you must add the color to the front of the parameter, that is, the color value is inserted where you want to change the color, For example, we let the user name display in red command should be:
\[\033[1;31;40m\]\[email protected]\h:\w\$ '
< Span class= "number" > &NBSP;
After you enter this code at the end of the current file in the Open editor, press Ctrl+s to save it. You can then close the editor directly by closing the editor, or you can press CTRL + C in the terminal to close the compiler and continue executing the command (note that you can continue the command only if you close the editor).
3, restart the terminal, you can see your color.
The following is the process of color matching:
Foreground background color
30 40 Black
31 41 Red
32 42 Green
33 43 Yellow
34 44 Blue
35 45 Purple Red
36 46 Blue
37 47 White
1 Transparent Color
Code meaning
0 OFF
1 highlighting
4 Underline
5 Flashing
7 Anti-white display
8 Not visible
Ubuntu modifies the color of the terminal