Linux Modify shell command prompt and color

Source: Internet
Author: User
Tags aliases

1. Load the configuration file sequence during the Linux login process:


/ETC/PROFILE→/ETC/PROFILE.D/*.SH→~/.BASH_PROFILE→~/.BASHRC→[/ETC/BASHRC]


Cat ~/.BASHRC #查看 ~/.BASHRC

#. BASHRC

# User specific aliases and functions

# Source Global Definitions

if [-F/ETC/BASHRC]; Then

. /etc/bashrc

Fi



2. shell command prompt and color is configured by PS1:


echo $PS 1

[\[\e[32;40m\]\[email protected]\w]

The parameters commonly used in PS1 are as follows:


\d: #代表日期, formatted as weekday month date, for example: "Mon-1"

\h: #完整的主机名称

\h: #仅取主机的第一个名字

\ t: #显示时间为24小时格式, such as: HH:MM:SS

\ t: #显示时间为12小时格式

\a: #显示时间为24小时格式: hh:mm

\u: #当前用户的账号名称

\v: #BASH的版本信息

\w: #完整的工作目录名称

\w: #利用basename取得工作目录名称, so only the last directory is listed

\#: #下达的第几个命令

\$: #提示字符, if it is root, the prompt is: #, the average user is: $



3. Color value settings:


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. 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 Purplish red

36 46 Cyan Blue

37 47 White

Depending on the color table, the color of the Linux Terminal command line can be personalized by applying the character color formatting. For example, to set the command line format for the green Word black, display the current user's account name, the first name of the host, the full current working directory name, 24-hour format time, you can use the following command:

#PS1 = ' [\[\e[32;40m\]\[email protected]\h \w \t]$ '



Configuration of the 4.~/.BASHRC:


Cat ~/.BASHRC

#. BASHRC

# User specific aliases and functions


Export ps1= ' [\[\e[32;40m\]\[email protected]\w]\$ ' #绿字体, black background, because the color output is not turned off, the command line's

His input will also be a green font, black background.


# export ps1= ' [\[\e[31;1m\]\[email protected]\h \w]\$\e[0m ' #红字体, bold and bright background. Can be closed by "\e[0m"

Color output, and when B is 1 o'clock, the highlighted bold text is displayed.

# Source Global Definitions

if [-F/ETC/BASHRC]; Then

. /etc/bashrc

Fi



5. After the modification is complete, reload the next ~/.BASHRC:


SOURCE ~/.BASHRC





Linux Modify shell command prompt and color

Related Article

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.