Set font and background color under BASH shell
\e[30m change the display color of a character to black
\e[31m change the display color of a character to red
\e[32m change the display color of a character to green
\e[33m change the display color of a character to light red
\e[34m change the display color of a character to blue
\e[35m change the display color of a character to purple
\e[36m change the display color of a character to light blue
\e[37m change the display color of a character to Gray
\e[40m--\e[47m Set background color
\e[40m setting the background color to black
\e[41m setting the background color to red
\e[42m setting the background color to green
\e[43m setting the background color to light red
\e[44m set the background color to blue
\e[45m set the background color to purple
\e[46m setting the background color to light blue
\e[47m setting the background color to gray
Set the output effect of the Linux shell [font color, style, etc.]
Echo-e "\033[32;49;1m [done] \033[39;49;0m"
Output result: [Done]
###########################
The color of the text terminal can be generated by using the ANSI unconventional character sequence. Example:
Echo-e "\033[44;37;5m ME \033[0m COOL"
The above command sets the background to blue, foreground white, blinking cursor, output character "ME", then reset screen to default settings, output character "COOL". "E" is an optional option for the command echo, which is used to activate the parser for special characters. "\033" guides the non-regular character sequence. "M" means to set the property and then end the unconventional character sequence, the real valid characters in this example are "44;37;5" and "0".
modifying "44;37;5" can produce combinations of different colors, which are not related to the sequence of values and encodings. The encoding you can choose is as follows:
Coded Color/action
0 Reset properties to default settings
1 setting Bold
2 Set half brightness (simulates color of color display)
4 Set underline (simulates color of color display)
5 Setting flashes
7 Setting the reverse image
22 Setting general Density
24 Turn underline off
25 Flashing off
27 Turn off reverse image
30 setting Black foreground
31 set Red foreground
32 Setting Green foreground
33 Setting Brown foreground
34 Set Blue Foreground
35 Setting Purple foreground
36 Setting the Cyan foreground
37 Setting White foreground
38 underline on the default foreground color
39 Turn the underline off on the default foreground color
40 Setting a black background
41 Setting the red background
42 Setting the green background
43 Setting the brown background
44 Setting the blue background
45 Setting purple Background
46 Setting the Cyan background
47 Setting a white background
49 Setting the default black background
Other interesting codes are:
\033[2J Clear the screen
\033[0q Turn off all keyboard LEDs
\033[1q Setting the "SCROLL Lock" indicator (Scroll Lock)
\033[2q Setting the value Lock indicator (Num lock)
\033[3q Setting the CAP Lock indicator (CAPS LOCK)
\033[15:40h move off to line 15th, column 40
\007 beep of the hair bee
#######################
How to change the font and background color of Redhat:
Command:
Ps1= "[\e[32;1m\[email protected]\h \w]\\$"
Or
Export ps1= "[\e[32;1m\[email protected]\h \w]\\$" The difference between the two see the relevant information about the environment variables
Explain:
\e[32;1m: This is the escape character that controls the font and background color, 30~37 is the font color, 40~47 is the background color
Example of the position of the 32;1m number can be swapped, such as \e[1;32m, if it is in the X environment can be replaced 1 of the range 0~10, there may be no use: 0 or do not write (\e [0;32m or \e[;32m) display light color, 1: Display highlighting 4: underline ... If the effect is not good, but can not be restored, then do not write the number in front of M, such as \e[32;m, or directly logout and landing
\u \h \w: Here are some escape characters, explained in detail below:
\d: Represents the date, formatted as weekday month date, for example: "Mon-1"
\h: The full host name. For example: My machine name is: Fc4.linux, then this name is Fc4.linux
\h: Only the first name of the host is taken, as in the example above, then Fc4,.linux is omitted
\ t: Display time in 24-hour format such as: HH:MM:SS
\ t: Display time in 12-hour format
\a: Display time in 24-hour format: hh:mm
\u: Current user's account name
Version information for \v:bash
\w: The full working directory name. Home directory will be replaced by ~
\w: Use basename to get the working directory name, so only the last directory is listed
\#: The first few commands issued
\$: Prompt character, if root, Prompt is: #, normal user is: $
\ n: Create a new row
The font is not limited to one color and can have multiple colors:
Ps1= "[\e[32;1m\[email protected]\e[35;1m\h \e[31;1m\w]\\$"
The above two commands after logging off and then landing on the invalid, the following method to make it permanent effect:
Vi/etc/profile
Add a line under "Export PATH ...": Export ps1= "[\e[32;1m\[email protected]\h \w]\\$"
Log out and then log in, it succeeds, if not effective, use the Source/etc/profile command to try, or directly restart the machine.
Set font and background color under Linux BASH shell