LinuxPS1 prompt definition

Source: Internet
Author: User
Article Title: linuxPS1 prompt definition. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Note:

Usage:

# PS1 = 'custom Content'

Note the single quotation marks on both sides.

Example: PS1 = '(\ u @ \ H \ d \ t) \ $'

Bytes ----------------------------------------------------------------------------------------------------------------

PS1: the user's usual prompt.

PS2: the first line is not complete. Wait for the prompt entered in the second line.

Linux system prompts are defined by the system variable ps1. The default format is [username @ host working directory] $.

Use echo $ PS1 to obtain the PS1 value, that is, PS1 = "[\ u @ \ h \ w]" \ $

After logging on, you can change the display style of PS1. However, after you log on to the system from the left-side Navigation Pane and log on to the system, the style changes to the default style of the system. If you want to completely change the style of PS1, it can only be changed from the configuration file.

PS is defined in. bash_profile under the user root directory.

For example

#. Bash_profile

# Get the aliases and functions

If [-f ~ /. Bashrc]; then

.~ /. Bashrc

Fi

# User specific environment and startup programs

# The following are the set PS1 values.

PS1 = "[\ u @ \ h \ w] \ $"

PATH = $ PATH: $ HOME/bin

# Use export to output PS1 so that it can take effect in the sub-shell, which causes the ROOT user to also use this style

# Use export PS1 with caution

Export PATH

Unset USERNAME

The following describes the meaning of the default special symbols in the environment:

\ D: represents the date, in the format of weekday month date, for example: "Mon Aug 1"

\ H: complete host name. For example, if my machine name is fc4.linux, this name is fc4.linux.

\ H: only the first name of the host. In the preceding example, the name is fc4, and the name of. linux is omitted.

\ 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. In the home directory ~ Replace

\ W: Use basename to get the working directory name. Therefore, only the last directory is listed.

#: Commands issued

\ $: The prompt character. If it is root, the prompt is: #, and the normal user is: $

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


We can set the PS1 variable to make the prompt color. In PS1, set the Character Sequence color format:

\ [\ E [F; Bm \]

''F'' indicates the font color, ranging from 30 to 30 ~ 37; ''B 'indicates the background color, numbered 40 ~ 47.

You can use ''\ e [0m'' to disable color output. In particular, when B is set to 1, the highlighted and bold text is displayed. For details, see the following color table and code table.

Color Table

Foreground background color
---------------------------------------
30 40 black
31 41? Color
32 42? Color
33 43? Color
34 44? Color
35 45 purple? Color
36 46 Qing? Color
37 47 white

Code meaning
-------------------------
0 OFF

1 highlighted

4 underline

5 flashes

7. Reverse display

8 invisible


If you want to set the terminal prompt style, set $ PS1 in ~ /. Bahrc specifies the ratio. For example, my settings are as follows:

Configuration 1:

PS1 = "\ [\ e [32m \] [\ u @ \ h \ w] $ \ [\ e [m \]"

Export PS1

Effect:

[LinuxSong @ test ~] $

Configuration 2:

If [$ TERM = 'linux ']; then
Export PS1 = "[\ [\ e [36; 1m \] \ u @ \ h \ [\ e [31; 1m \] \ w \ [\ e [32; 1 MB \]>"
Zhcon -- utf8
Clear
Elif [$ TERM = "xterm"]; then
Export PS1 = "[\ [\ e [31; 1m \] \ w \ e [0 m]>"
Fi

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.