Font color settings on the Linux terminal interface

Source: Internet
Author: User

Font color settings on the Linux terminal interface

Directory

Description
PS1
Color syntax
Save settings

Description
I found a lot of information on the Internet, which is not very detailed, or there is a syntax error.
So it took a long time to understand it. It was easy to write it down for later people to learn.
Other Linux Virtual Machine versions of CentOS 6.5 may be slightly different.

PS1
PS1 is an environment variable for Linux end users. It is used to describe the settings of command line prompts. Input the command echo $ PS1 on the terminal to output the definition of PS1:

PS1 = '[\ u @ \ h \ W] $'

The default command line prompt for linux is: [the account name of the current user @ the last item of the working directory of the first name of the Host] $
The definitions of common parameters in PS1 are as follows:

\ D: # represents the date, in the format of weekday month date, for example: "Mon Aug 1"
\ H: # complete host name
\ H: # Only the first name of the host
\ 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 information
\ W: # complete working directory name
\ W: # Use basename to get the working directory name. Therefore, only the last directory is listed.
##: # Commands
\ $: # Prompt character. If it is root, the prompt is: #, and the normal user is: $

Color syntax
The color format is \ [\ e [F; Bm] and ends with \ e [m

F B Color
30 40 Black
31 41 Red
32 42 Green
33 43 Yellow
34 44 Blue
35 45 Purple red
36 46 Blue
37 47 White

For example, we want to change the \ u color.

PS1 = "[\ [\ e [31; 40 m] \ u \ e [m @ \ h \ W] \ $"

In this way, the color of \ u is set to red and the background color is black.
Modified:

For example

PS1 = "[\ u \ [\ e [31; 40 m] @ \ e [m \ [\ e [36; 40 m] \ h \ e [m \ [\ e [31; 40 m] \ W \ e [m] \ $"

The @ symbol is changed to the foreground color, the red background color is black, the \ h is the foreground color, the blue background color is black, and the \ W is the foreground color is the red background color is black.

Modified:

Save settings
Write the configured PS1 variable to. bashrc so that all the enabled terminals are valid.

$ Cd ~
$ Vi. bashrc
Add a row after opening

PS1 = "[\ u \ [\ e [31; 40 m] @ \ e [m \ [\ e [36; 40 m] \ h \ e [m \ [\ e [31; 40 m] \ W \ e [m] \ $"

Save and exit.

This article permanently updates the link address:

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.