Recently, we have been using the Linux operating system (cent5.0) because of our work needs ). I hate Linux terminal command line unchanged style, and it is not easy to distinguish from the output content, it is easy to see. So I went online and found a method to modify the command line color of the Linux terminal. I verified those methods and finally found a valid method to modify the command line color of the Linux terminal. (Take the root user as an example)
1. PS1
To modify the command line color of a Linux terminal, we need to use ps1, which is an environment variable of the Linux terminal user to describe the settings of the command line prompt. Enter the command # Set in the terminal to find the definition of PS1 in the output:
PS1 = '[\ U @ \ H \ W] \ $'
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 is used.
\ 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.
\:# 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, so only the last directory will be listed
\#: # Commands
\ $:# Prompt character. If it is root, the prompt is: #, and the normal user is: $
From this, we can see that the default command line prompt information in Linux is: [the account name of the current user @ the last entry of the first name working directory of the Host] #
2. color settings
In ps1, set the Character Color format to \ [\ e [F; BM \], where "F" is the font color, numbered 30-37, "B" is the background color, numbered 40-47. The color table is as follows:
F B
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
According to the color table, apply the character color settings in the format, you can customize the Linux terminal command line color settings. For example, to set the command line format to a black box, display the account name of the current user, the first name of the host, the complete name of the current working directory, and the 24-hour format time, you can use the following command:
# PS1 = '[\ [\ e [32; 40m \] \ U @ \ H \ W \ t] $'
3. Modify the. bashrc File
Through the above settings, only the command line format of the current terminal can be changed. to close this terminal, the command line format in the re-opened terminal will be restored to the default format. To change the terminal command line format permanently, You need to modify the. bashrc file.
Run the following command: # cd/
# Ls-l-
You can see the. bashrc file. Use commands
# Gedit. bashrc
Add the. bashrc File
PS1 = '[\ [\ e [32; 40m \] \ U @ \ H \ W \ t] $'
Save this statement to change the terminal command line format permanently.