Linux command line prompt settings

Source: Internet
Author: User

We use the Linux system when the most contact is its command line window, many times we need to enter commands on the command line, before the input command will have a prompt, the general system default prompt form is: [[email protected] working directory]$.

In fact, we can customize the command line prompt for ourselves, the Linux system prompt is defined by the system variable PS1, as long as the value of the PS1 system variable is modified by the rules arbitrarily modify the command line prompt.

From the command Echo $PS 1 View the value of the PS1, which is ps1= "[\[email protected]\h: \w \t]\$". After you modify the value of PS1, the value of PS1 changes back to the default value after you restart the system or log back in. If you want to permanently save the PS1 value to the user, you can re-import the new value of the system variable PS1 by modifying the user profile. Profiles.

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


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 ', in particular, when B is 1 o'clock, the highlighted text is displayed in detail in the following color table and 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 style of the terminal prompt just specify the $PS1 in ~/.BAHRC, for example my settings are as follows:
Set One:

Ps1= "" ["e[32m"][\[email protected]\h \w] $ "[" E[m "]"
Export PS1

Effect:

[Email protected] ~]$

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

The article is posted in the blogger's website Lang degree cloud, transmission door:

Http://www.wolfbe.com/detail/201608/280.html

Linux command line prompt settings

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.