1. What is a command prompt
Command Prompt is the CLI (command-line interface, command line interface) in the process of human-computer interaction prompts the user to be able to enter the command of the special symbol, in Linux, the average user prompt "$", the root user's prompt "#". Of course there are some special strings in front of you.
Like what:
[Email protected]:~> Doge is the user name of the current user, Linux-uqf4 is the hostname, ~ Indicates the current directory is the Dodge of the home directory (or home directory).
2. What is the command prompt for?
Command prompt can give us a hint, by modifying, you can add any string you want in the command prompt, such as time, user name, host name, Shell version of the current working directory. Even a motto is also possible.
3. How do I change the command prompt?
The bash shell environment of the Linux system is usually determined by PS1, which is the bash built-in variable that determines the display format of the main command prompt, and we just need to set this variable to the format we want to get the visual effect we wanted.
You can view PS1 variables by Ehco
First, show Hello World at the command prompt,
[Email protected]:~> export ps1= "Hello World:" Hello world:lsbin public_html public template video picture Document Download music
Here you can. "Hello World in double quotes: replace any strings you want."
Of course, some escape characters are defined in bash and can be used to output specific content.
In the PS1 variable we can use some of the following well-defined content, and I can output what we need with a combination of normal strings and these characters:
\d : "Wed Sep 06" format date \ t : 24-hour time \ t: 12-hour time \@ : 12-hour time with am/pm \e : ASCII escape character \a : ASCII Bell character (you can also type \007) \ r : Carriage return \ n : newline character \h : hostname \h : full hostname \j : Number of processes suspended in this shell by ^z : this Shell's terminal name (such as "TTYP1") \s : Shell name (e.g. "bash") \v : Bash version (e.g. 2.04) \v : Bash version (including patch level) \u : User name \w : Current working directory (absolute Path) \w : The main file name part of the current working directory \! : The current command is in the position of the historical buffer \$ : If the UID of the current user is 0 (that is, root), the character # is inserted, the other user inserts the character $\\ : Backslash \[ : The beginning of the non-printable string \] : The end of the non-printable string NNN : Octal escape character
You can add the above content to your string.
For example, I would like to turn just "Hello World:" into "Hello Username:"
Hello world:export ps1= "Hello \u:" Hello dodge:lsbin public_html public template video picture document Download Music
This is a combination of me export ps1= ' [\[email protected]\h \w]\$ '
Of course not only how the command line can be highlighted in reality, that is, we can change the color of the output font.
For example, if you enter the following command
printf ' \e[1;31mhello world\e[0m\n '
In the command line, it will output a red Hello world.
Let's parse some, first take out the middle Hello World, and then remove the last \ n Escape line break. and the "\e[1;31m \e[0m" left.
The front \e[1;31m tells the command line that I want to output lines of red words, highlighted.
\e[0m tell the command line, no longer output red words, why go!!
This shows that the command line understands some special string sequences as attributes of character output.
Let's take a look at how to define these special sequences of characters:
\[\e[property; font Color m\] #设置属性和字体颜色: \[\033[property; font Color m\] #同上 \[\e[property; font color; background color m\] #设置属性和字体颜色和背景色 \[\033[property; font color; Background color m\] #同上
\[\e[0m\] #结束字符颜色输出, restore default color settings
The character color and background colors are defined as follows
Foreground background color, black, red, green, yellow, Blue . Black Blue panax notoginseng White
The character attribute properties are defined as follows
Code behavior 0 OFF1 highlighting 4 underline5 flashing 7 anti-white display 8 not visible
This way I can have my command prompt Fugauliang displayed by the following command.
Export ps1= ' [\[\e[1;37m\]\[email protected]\h \w\[\e[0m\]]\$ '
It is particularly impersonal to enter such a day command every time you run the command line. So we can get him to load automatically when the system logs on.
When Linux starts, load/etc/profile--/etc/profile--and/etc/profile.d/*.sh---~/.bash_profile SHRC, [/ETC/BASHRC]
So we can put the order in the ~/.BASHRC, so we can.
How Linux modifies the command prompt