PS1 variable configuration under Linux environment

Source: Internet
Author: User
Tags word wrap

My PS1 command prompt: ps1= "\[\e[32;40m\][\[\e[32;40m\]\u \[\e[32;40m\]>>\h \[\e[32;40m\]\w \[\e[36;40m\] (\A) \[\e[32; 40m\]] \[\e[0m\]\$ "

1. Set the display of PS1 face

PS1 (is the number 1 instead of the letter L), each version of Bash's PS1 variable within the special symbol may be a little different, you can first man bash. The following are the meanings of the default special symbols in the FC4 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: Take the first name of the host only, 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: $

The default PS1 content is: ps1= ' [\[email protected]\h \w]\$ ', so the default prompt is: [[email protected] ~]#.

PS: This section content reprint from

2. Set the color of the PS1 variable

We can make a prompt color by configuring the PS1 variable. The format for configuring character sequence colors in PS1 is:     \[\e[f; bm\]     is basically a numeric value sandwiched between "\e[" (escaped square brackets) and "M". If you specify more than one numeric code, separate them with semicolons.         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 and the highlighted text is displayed, see the Color table and the code table below.      Color Table      foreground background color    ---------------------------------------    30 40 Black     31 41 red     32 42 green     33 43 yellow     34 44 Blue     35 45 Purple     36 46 Cyan     37 47 white      code meaning    -------------------------    0 OFF&N Bsp   1 highlighting     4 underline    5 blinking     7 anti-white display     8 invisible      If you want to configure the end The style of the end prompt can only be specified by $PS1 in ~/.BAHRC   "\e[0m"   If the numeric code is specified as zero, he will notify the terminal to reset the foreground, background and bold configuration to their default values. You may use this code at the end of the cue line to make the text you type non-colored. Now, let's take a look at these color codes. Note the following screenshot results:   to use this table, first find the color you want to use, and then look for the corresponding foreground number (30-37) and background number (40-47). For example, if you likeGreen characters on black, you can set the numbering to 32 and 40 respectively. Then open your cue line definition and add the appropriate color code to it. The following definition:   export ps1= "\w>"    changed to:   export ps1= "\e[32;40m\w>"    so far, The cue line, though very good, is still not perfect. After bash shows the working directory, we need to reconfigure the colors to normal values using the "\e[0m" sequence.   export ps1= "\e[32;40m\w> \e[0m"    This definition will show a nice green cue line, but we still need to do some cleanup work. We don't need to include a background color configuration of "40" because he configures the background as black, and black is the default color. In addition, Green is still very dark; we fix this problem by adding a "1" color code, which will enable brighter bold text. In addition to this modification, we also need to enclose all nonprinting characters in the dedicated bash escape sequence "\[" and "\". These two sequences inform bash that the enclosed characters do not occupy any space on the line, so that the word wrap continues to function properly. There are no two escape sequences, although you have a nice hint line, but if you type a command that happens to the right end of the terminal, it will cause confusion. PS: This section reprint from

PS1 variable configuration under Linux environment

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: 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.