Linux PS1 prompt definition

Source: Internet
Author: User

Linux PS1 prompt definition

  PS1: Is the user's usual prompt.
PS2: The first line is not finished, wait for the second line to enter the prompt.

The Linux system prompt is defined with the system variable PS1. The general system default form is: [username@host working directory]$.
Use echo $PS 1 to get the PS1 value, i.e. ps1= "[\[email protected]\h \w]" \$
After logging in, you can change the display style of the PS1, but when you exit the restart login system, the style becomes the default style of the system, if you want to completely change its style, can only be changed from the configuration file.
PS is defined in the. bash_profile in the user root directory.

Such as

#. Bash_profile

# Get the aliases and functions

If [-f ~/.BASHRC]; Then

. ~/.bashrc

Fi

# User specific environment and startup programs

#以下是设定的PS1的值

Ps1= "[\[email protected]\h \w]\$"

Path= $PATH: $HOME/bin

#使用export把PS1输出 so that it can take effect in the child shell, which causes the root user to also use this style

#export PS1 to use with caution

Export PATH

Unset USERNAME

The following is a brief talk about the meaning of the default special symbols in the environment:

\d: Represents the date, formatted as weekday month date, for example: "Mon-1"

\h: The full host name. For example: My machine name is: Fc4.linux, then this name is Fc4.linux

\h: Only the first name of the host is taken, as in the example above, then Fc4,.linux is omitted

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

\ t: Display time in 12-hour format

\a: Display time in 24-hour format: hh:mm

\u: Current user's account name

Version information for \v:bash

\w: The full working directory name. Home directory will be replaced by ~

\w: Use basename to get the working directory name, so only the last directory is listed

\#: The first few commands issued

\$: Prompt character, if root, Prompt is: #, normal user is: $

==================================================

We can make a prompt color by setting the PS1 variable. The format for setting character sequence colors in PS1 is:
\[\e[f; Bm\]
Where ' F ' is the font color, number 30~37; ' B ' is the background color, number 40~47.
The color output can be turned off by ' \e[0m ', especially when B is 1 o'clock, the highlighted text will be displayed in detail, please see the color table below and the Code table.

Color table

Foreground background color
---------------------------------------
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

Code meaning
-------------------------
0 OFF
1 highlighting
4 Underline
5 Flashing
7 Anti-white display
8 Not visible


If you want to set the terminal prompt style as long as the $PS1 in the ~/.BAHRC specified can be compared, such as my settings are as follows:
Set One:
ps1= "\[\e[32m\][\[email protected]\h \w]$\[\e[m\]"
Export PS1
Effect:
[Linuxsong@test ~]$

Set two:

if [$TERM = ' Linux ']; Then
Export ps1= "[\[\e[36;1m\]\[email protected]\h \[\e[31;1m\]\w\[\e[32;1m\]]>"
Zhcon--utf8
Clear
elif [$TERM = "xterm"]; Then
Export ps1= "[\[\e[31;1m\]\w\e[0m]>"
Fi


Linux PS1 prompt definition

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.