Linux Command Line prompt settings, linux Command Line prompt
The command line window is the most commonly used in Linux. In many cases, you need to enter commands on the command line. A prompt is displayed before the command is entered, the default prompt format is [username @ host working directory] $.
In fact, we can customize a customized command line prompt for ourselves. The Linux system prompt is defined by the system variable PS1, as long as you modify the value of the PS1 system variable according to the rule and modify the command line prompt at will.
Run echo $ PS1 to view the PS1 value, that is, PS1 = "[\ u @ \ h: \ w \ t] \ $ ". After you modify the value of PS1, the value of PS1 is changed back to the default value after you restart the system or log on again. If you want to permanently Save the PS1 value for the user, you can modify the user configuration file. profile to re-import the new value of the system variable PS1:
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
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 colors
32 42 colors
33 43 colors
34 44 colors
35 45 Violet colors
36 46 green colors
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 ~ /. You can specify bahrc. For example, my settings are as follows:
Configuration 1:
PS1 = "" ["e [32 m"] [\ u @ \ h \ w] $ "[" e [m "]"
Export PS1
Effect:
[Wolfbe @ test ~] $
Configuration 2:
if [ $TERM = 'linux' ]; then
export PS1="["["e[36;1m"]"u@"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 published simultaneously on the blog master's website:
Http://www.wolfbe.com/detail/201608/280.html