Linux Shell Command Prompt and color modification, linuxshell

Source: Internet
Author: User

Linux Shell Command Prompt and color modification, linuxshell

1. Sequence of loading configuration files during Linux Logon:

/Etc/profile →/etc/profile. d/*. sh → ~ /. Bash_profile → ~ /. Bashrc → [/etc/bashrc]
You can view the default ~ The/. bashrc file is as follows:

1 [root@localhost ~]$ cat ~/.bashrc 2 # .bashrc3 4 # User specific aliases and functions5 6 # Source global definitions7 if [ -f /etc/bashrc ]; then8     . /etc/bashrc9 fi

2. The Shell command prompt and color are configured by PS1:

1 [root@localhost ~]$ echo $PS12 \[\e[32;40m\][\u@\h \W]$\e[m

The common parameters of 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
\ 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.
\ A: # 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. Therefore, only the last directory is listed.
##: # Commands
\ $: # Prompt character. If it is root, the prompt is: #, and the normal user is: $

3. Set the color value

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. Set the ending color with \ e [m. 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]\$'

 

4. Take the author's ~ /. Bashrc configuration example
 1 [root@localhost ~]$ cat ~/.bashrc 2 # .bashrc 3  4 # User specific aliases and functions 5  6 alias rm='rm -i' 7 alias cp='cp -i' 8 alias mv='mv -i' 9 10 PS1="\[\e[32;40m\][\u@\h \W]\$\e[m "11 12 # Source global definitions13 if [ -f /etc/bashrc ]; then14     . /etc/bashrc15 fi

 

5. Modify in vim or nano

Reload ~ /. Bashrc takes effect:

[root@localhost ~]$ source ~/.bashrc

 

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.