Linux Terminal Color Control

Source: Internet
Author: User

Introduction: Because in the C code to see the printing color word, and PS1 want to know more, only this blog post.
----------------------------------------
Linux Terminal Console Font Color
----------------------------------------
Linux Terminal console font color, using an escape sequence
\e[f; B;om
The \e escape character starts, and the ESC ASCII code is 27, which equals 033 in octal notation.


\e or \033 declares the beginning of the escape sequence,
[Start defining colors.]
' F ' for font color, number 30~37;
' B ' is the background color, number 40~47.
' O ' for special meaning code
Their order is not related.
M is the mark
m not followed by spaces, is defined by the color Word and background
Color table
Foreground background color
-------------------------
30 40 Black
31 41 Red
32 42 Green
33 43 Yellow
34 44 Blue
35 45 Magenta
36 46 Cyan
37 47 White

Special code meaning
-------------------------
0 OFF
1 highlighting
4 Underline
5 Flashing
7 Anti-white display
8 Not visible


Application 1: Interpreting the colored PS1
ps1= "\[\e[32m\][\[email protected]\h \w]$\[\e[m\]"
Explanation: \[\] for group representation
Define [\[email protected]\h \w]$ as foreground color green. Then restore the default settings.

Application 2: Use the console to output color or color backgrounds
Echo-e "\033[34;1mthis is high lighted blue \033[0m"
C Code: printf ("\033[34;1mthis is high lighted blue \033[0m\n");
The tail \033[0m restores the system default color

Linux Terminal Color Control

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.