Custom shell terminal prompt and color (for CentOS as an example)

Source: Internet
Author: User
Tags aliases

Linux Modify shell command prompt and color

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:

[Root@~/wade/codereview/redis-2.8.17Cat ~#. BASHRC # User specific aliases and functions c10># Source Global Definitions/etc/bashrcfi       

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

[Root@/etc/init.d$PS 1[\[\e[32;40m\   ]\u@\w]
[\[email protected]\h: \w]\$ #本人使用的格式, Record!

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 \#: #下达的第几个命令 \$: # Prompt character, if root, the prompt is: #, the average user is: $

3. Color value setting: The format of 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 Front color  b background Color      black-      red-      Green-yellow      -      Blue      45      purplish red,      cyan Blue,      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:

[Root@~]# BASHRC # User specific aliases and functions # #用户特定的别名和函数即用户定义变量ps1=' [\[\e[32;40m\] \[email protected]\w]\$ ' # source Global definitions definition of #全局 sources/etc/etc /bashrcfi  

5. After the modification is completed, reload the next ~/.BASHRC to take effect:

| Linux file color, cp /etc/dir_colors ~/.dircolors first back up one, and then modify!
Color scheme Ibid.
|

Custom shell terminal prompt and color (for CentOS)

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.