Set the color of the text terminal in Linux

Source: Internet
Author: User
Tags echo command
Set the color of the text terminal in Linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. An escape sequence character usually starts with ESC and is recorded as "^ [" in Shell, and is often recorded as \ 033 (because ESC is 27 in ASCII encoding, octal is recorded as 033 ).

The color of the text terminal can be generated using an ANSI unconventional character sequence.

Example:

Echo-e "\ 033 [44; 37; 5 m ME \ 033 [0 m COOL"

Echo-e "\ 033 [33; 40; 4mMM \ 033 [0 m"

The above command sets the background to blue, foreground white, blinking cursor, output character "ME", then reset the screen to the default settings, and output the character "COOL ". "E" is an option for the echo command, which is used to activate the parser for special characters. "\ 033" directs the sequence of unconventional characters. "M" means setting the attribute and ending the unconventional Character Sequence. In this example, the valid characters are "44; 37; 5" and "0 ".

Modify "44; 37; 5" to generate a combination of different colors. The values are irrelevant to the order of encoding. The optional encoding is as follows:

Encoding color/Action
0. Reset the property to the default setting.
1. Set bold
2. Set half brightness (simulate color display)
4. Set the underline to simulate the color of the color display)
5. Set flashing.
7. Set reverse Images
22. Set the general density
24. Close the underline
25 turn off flashing
27 disable reverse image
30 set the black foreground
31 set the red foreground
32. Set the green foreground
33 set the brown foreground
34 set the blue foreground
35 set purple foreground
36 set the blue foreground
37 set the white foreground
38. Set the underline on the default foreground color
39. Disable the underline on the default foreground color
40 set a black background
41 set the red background
42 set a green background
43 set brown background
44 set the blue background
45 set a purple background
46 set the blue background
47 set the white background
49 set the default black background

Other interesting code:

\ 033 [2J clear screen
\ 033 [close all keyboard lights with 0q
\ 033 [1 Q: Set the "Scroll Lock" indicator (Scroll Lock)
\ 033 [set the "numerical Lock" indicator (Num Lock) for 2q)
\ 033 [set "Caps Lock" for 3q)
\ 033 [15: 40 H move close to 15th rows, 40 Columns
\ 007 beep

To learn more, run the man console_codes command.
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.