Linux username, host add background color

 Article reference: PS1 application - modify the font color of the linux terminal command line

 

  The background color of Linux user name and host is added for production environment, which can reduce human misoperation.

 

1 [root@zhang ~]# tail /etc/bashrc
2 ………………
3 export PS1="\[\e[37;40m\][\[\e[37;41m\]\u\[\e[37;41m\]@\h\[\e[37;40m\] \W\[\e[0m\]]\\$ "

  The result is as follows: 

 

1. Get to know the PS1

  PS1 is an environment variable for Linux terminal users that defines the parameters of the command line prompt. The default is as follows:

1 [root@zhang ~]# echo $PS1
2 [\u@\h \W]\$

  It means: [the current user's account name@the first name of the host name and the last layer of the directory name of the working directory]#

 

Common parameters and meanings of PS1:

  \d : represents the date, the format is weekday month date, for example: "Mon Aug 1"

  \H : full hostname

  \h : take only the first name in the hostname

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

  \T : Display time in 12-hour format

  \A : Display time as 24 hours format: HH:MM

  \u : the account name of the current user

  \v : BASH version information

  \w : full working directory name

  \W : Use basename to get the working directory name, only the last directory name is displayed

  \# : the number of commands issued

  \$ : Prompt character, if it is a root user, the prompt is # , for ordinary users it is $

 

2. Color setting parameters

 

 The format for setting character color in PS1 is: \[\e[F;Bm\]........\[\e[0m\], where "F" is the font color, numbered 30-37 , "B" is the background color, numbered 40-47, \[\e[0m\] as the end of the color setting.

  Color comparison table:

    F    B

    30 40 black

    31 41 red

    32 42 Green

    33 43 Yellow

    34 44 blue

    35 45 Fuchsia

    36 46 Turquoise

    37 47 white

   Just insert the corresponding number into the setting format.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325633873&siteId=291194637