Linux shell Output Effect modification method (interface color) _linux shell

Source: Internet
Author: User
Tags clear screen
The color of the text terminal can be generated using the ANSI non-normal character sequence. Example:
Echo-e "\033[44;37;5m ME \033[0m Cool"
The above command sets the background to blue, the foreground is white, the blinking cursor, the output character "ME", and then reset the screen to the default settings, the output character "cool". "E" is an optional option for command Echo, which activates the parser for special characters. "\033" boots a sequence of unconventional characters. "M" means setting the property and then ending the unconventional sequence of characters, in this case the "44;37;5" and "0" characters are really valid.
modifying "44;37;5" can produce combinations of different colors, and the values are not related to the order in which they are encoded. The encodings you can choose are as follows:

coded color/action
0 Reset properties to default settings
1 set Bold
2 Set half brightness (simulate color of color display)
4 Set underline (simulate color of color display)
5 Setting Flicker
7 Setting the reverse image
22 Setting general Density
24 Off underline
25 off flashing
27 Turn off the reverse image
30 setting Black foreground
31 Setting the red foreground
32 Setting Green foreground
33 Setting Brown foreground
34 Setting Blue Foreground
35 Setting Purple foreground
36 Setting Cyan Foreground
37 Setting White foreground
38 underline on the default foreground color
39 Close the underline on the default foreground color
40 Setting black background
41 Setting Red background
42 Setting Green Background
43 Setting Brown background
44 Setting Blue background
45 Setting purple Background
46 Setting Cyan Background
47 Setting white background
49 Setting the default black background

Other interesting code is:

\033[2J Clear Screen
\033[0q Turn off all keyboard LEDs
\033[1q set the SCROLL lock LED (Scroll Lock)
\033[2q set the value Lock indicator (Num lock)
\033[3q Set CAPS LOCK LED (Caps Lock)
\033[15:40h, move the closure to line 15th, column 40.
\007 the Bee-born beep
#######################

How to change the font and background color of Redhat:

Command:
Ps1= "[\e[32;1m\u@\h \w]\\$"
Or
Export ps1= "[\e[32;1m\u@\h \w]\\$" The difference between the two please check the relevant information of 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
The position of the 32;1m number in the example can be reversed as \e[1;32m, if it is in the X environment can be replaced 1 of the range 0~10, may have no use: 0 or do not write (\e [0;32m or \e[;32m) display light color, 1: Show highlights 4: underlined ... If the effect of the change is not good, but can not be restored, then do not write m before the number, such as \e[32;m, or directly log off and then landed

\u \h \w: Here are some escape characters, explained in detail below:
\d: Represents a date, formatted as weekday month date, for example: "Mon Aug 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, as in the example above, is omitted for Fc4,.linux
\ t: Displays a time of 24-hour format, such as: HH:MM:SS
\ t: Display time in 12-hour format
\a: Display time is 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 will be listed
\#: The first few orders issued
\$: Prompt character, if root, the prompt is: #, the average user is: $
\ n: Create a new row
Fonts are not limited to one color and can have multiple colors:
Ps1= "[\e[32;1m\u@\e[35;1m\h \e[31;1m\w]\\$"
The above two commands are invalidated after logging off, and are permanently in effect in the following ways:
Vi/etc/profile
Add a row under "Export PATH ...": Export ps1= "[\e[32;1m\u@\h \w]\\$"
Log off and then log on, and if not, use the Source/etc/profile command to try, or simply reboot the machine.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.