Modify the color in shell in Linux

Source: Internet
Author: User
Tags echo command

Modify the color in shell in Linux
Echo-e "\ 033 [32; 49; 1 m [DONE] \ 033 [39; 49; 0 m" output result: [DONE] ########################## the color of a text terminal can use "ANSI unconventional characters sequence. Example: echo-e "\ 033 [44; 37; 5 m ME \ 033 [0 m COOL" and above commands set the background to blue, foreground white, blinking cursor, output the character "ME", and then reset the screen to the default setting, 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. You can select the encoding as follows: encoding color/Action 0 reset properties to the default settings 1 set bold 2 set half brightness (simulate color display color) 4. Set the underline to simulate the color of the color display) 5 set flashing 7 set reverse image 22 set general density 24 turn off underline 25 turn off blinking 27 turn off reverse image 30 set black foreground 31 set red foreground 32 set green foreground 33 set brown foreground 34 set blue foreground 35 set purple foreground 36 set cyan foreground 37 set white foreground 38 set underline on default foreground color 39 disable underline on default foreground color 40 set black background 41 set red background 42 set green background 43 set brown background 44 set blue background 45 set purple background 46 set blue background 47 set white background 49 set default black background other interesting codes are as follows: \ 033 [2J clear screen \ 033 [0q close all keyboard indicators \ 033 [1q set "scroll lock" "Indicator light (Scroll Lock) \ 033 [2q set" value Lock "indicator light (Num Lock) \ 033 [3q set" Capital Lock "indicator light (Caps Lock) \ 033 [15: move close to 15th rows in 40 H, beep for 40-column \ 007 beeps ####################### how to change the font and background color of RedHat: command: PS1 = "[\ e [32; 1m \ u @ \ h \ W] \ $" or export PS1 = "[\ e [32; 1 m \ u @ \ h \ W] \ $ "for the differences between the two, please refer to the Environment Variable related information explanation: \ e [32; 1 m: this is the escape character that controls the font and background color, 30 ~ 37 is the font color, 40 ~ 47 is the 32 in the background color example. The position of the 1 m digit can be reversed, for example, \ e [1; 32 m. If it is in the X environment, you can change the range of 1 to 0 ~ 10, some useless places: 0 or do not write (\ e [0; 32 m or \ e [; 32 m) Show light color, 1: Show highlighted 4: underline ..... if the effect is not good but cannot be restored, do not write the number before m, such as \ e [32; m, or log out directly and log on to \ u \ h \ W: this is an escape character. \ d: represents a date in the format of weekday month date. For example, "Mon Aug 1" \ H: complete host name. For example, if my machine name is fc4.linux, this name is fc4.linux \ h: only the first name of the host. In the preceding example, It is fc4 ,. linux is omitted \ t: The display time is in the 24-hour format, for example, HH: MM: SS \ T: The display time is in the 12-hour format \ A: The display time is in the 24-hour format: HH: MM \ u: Account name of the current user \ v: BASH version \ w: complete working directory name. In the home directory ~ Replace \ W: Use basename to get the name of the working directory. Therefore, only the last directory \ # is listed. For example, if it is root, the prompt is: #. For normal users, the value $ \ n indicates that the font of a new row is not limited to one color. It can have multiple colors: PS1 = "[\ e [32; 1 Mbit/s \ u @ \ e [35; 1 Mbit/s \ h \ e [31; 1 Mbit/s \ W] \ $ "the above two Commands will become invalid after logging out, use the following method to make it permanently effective: vi/etc/profile is in the "export PATH ..... "add a line below: export PS1 =" [\ e [32; 1m \ u @ \ h \ W] \ $ "log out and log on again. If the line does not take effect, use the source/etc/profile command or restart the machine.

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.