Modify the font color of the Linux terminal command line

Source: Internet
Author: User

Recently Learning Linux operating systems (CentOS 6 & CentOS 7). The Linux terminal command line is all white, which often causes the command and output to be difficult to distinguish. So on the Internet to find a way to modify the Linux terminal command line color, found by defining the PS1 environment variable can be implemented, below I as the root user operation.

1. Understanding PS1

PS1 is an environment variable for Linux end users that defines the parameters of a command-line prompt.


In the terminal input command:

grep PS1

You can get the definition value of the current PS1:

ps1="

Common parameters and meanings of PS1:

\d: Represents the date, formatted as weekday month date, for example: "Mon-1"

\h: Full host name

\h: Takes only the first name in the host name

\ t: Display time in 24-hour format such as: HH:MM:SS

\ t: Display time in 12-hour format

\a: Display time in 24-hour format: hh:mm

\u: Current user's account name

Version information for \v:bash

\w: Full working directory Name

\w: Use basename to get the working directory name, showing only the last directory name

\#: The first few commands issued

\$: Prompt character, if root user, prompt is #, normal user is $

So the format of the Linux default command line prompt information
ps1='[\[email protected]\h \w]\$ ' means: [Current user's account name @ hostname of the first name working directory last level directory name]#

2. Color Setting parameters

The format for setting the character color in PS1 is: \[\e[f; Bm\], where "F" is the font color, number is 30-37, "B" is the background color, number 40-47.

Color table:

F B

30 40 Black

31 41 Red

32 42 Green

33 43 Yellow

34 44 Blue

35 45 Purplish red

36 46 Cyan Blue

37 47 White

Simply set the corresponding number into the format.
For example, to set the command line format is the green character Black Bottom (\[\e[32;40m\]), display the current user's account name (\u), the host's first name (\h), the full current working directory name (\w), 24-hour format time (\ t), you can type the following command directly at the command line:

# ps1='

After many tests, I finally decided on a format that was right for me:

# ps1=""

But note that such a setting is temporary.

3. Modify the. bashrc file to permanently save the command line style.

The scope of the above settings is only valid for the current terminal's login, closing the terminal or exiting the login immediately expires. To permanently save the settings, you need to modify the. BASHRC configuration file.

Type the command:

1 # CD 2 ls -la

You can now see the. bashrc file.

Edit. BASHRC:

# vim. BASHRC

Join this line:

ps1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$ "

Save exit.

Reload Bash configuration file:

# source. BASHRC

can be applied immediately and permanently.

effect, no longer afraid in the vast sea of words to search for the whereabouts of the command line.

Note : This knowledge point is from the original author Bowen "Modify the command line Color Linux terminal", and made some improvements . Thanks to the author's still indifferent sharing .

Modify the font color of the Linux terminal command line

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.