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]
You can view the default ~/.BASHRC file as follows:

1 cat ~/2# BASHRC34# User specific aliases and functions  56# Source Global Definitions7ifthen8      . /etc/BASHRC9fi

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

1 Echo $PS 1 2 \[\e[, 40m\][\[email protected]\h \w]$\e[m

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. To end the color setting with \e[m, the color table is as follows:

F B
Black
Red
Green
Yellow
Blue
Purple Red
Green 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]\$'

4. Take the author's ~/.BASHRC configuration as an example
1[Email protected] ~]$Cat~/. BASHRC2 #. BASHRC3 4 # User specific aliases and functions5 6AliasRM='rm-i'7AliasCP='cp-i'8AliasMV='mv-i'9 Tenps1="\[\e[32;40m\][\[email protected]\h \w]\$\e[m" One  A # Source Global Definitions - if[-F/ETC/BASHRC]; Then -. /etc/BASHRC the fi

Modified under 5.vim or nano

Reload the next ~/.BASHRC to take effect:

[Email protected] ~]$ 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.