Fundamentals of the ten-year OPS series-Linux
Zeng Lin
Contact: [Email protected]
Website: www.jplatformx.com
Copyright: Please do not reprint the article without permission
First, Introduction
This section explains the small features of a Linux shell: the shell prompt. Like many programs in Linux, the shell prompt is highly configurable. Through the introduction, we will find the shell and terminal emulator program internal working mechanism.
Second, the decomposition of the prompt character
The system's default prompt looks as follows:
You can see that the prompt contains the user name, host name, and current working directory. The prompt is defined by an environment variable named PS1 (prompt string 1, which is the prompt string 1). Note: If the output is different from the sample, you do not need to worry about it. Each Linux distribution has a different definition of this prompt string, and some are even strangely defined.
As you can see, PS1 contains symbols that appear in the prompt, such as square brackets, the @ symbol, and the $ symbol, but the rest of the section is confusing. The escape characters used in the shell prompt are explained in detail.
Escape character |
Meaning |
\a |
ASCII ringtones. When the escape character is encountered, the computer will emit a sound |
\d |
The current date, expressed in the form of a week, month, or day, such as "Mon May 26" |
\h |
Host name of the local machine, but without domain name |
\h |
The full host name |
\j |
Number of tasks in the current shell session |
\l |
Name of the current terminal device |
\ n |
Line break |
\ r |
Carriage return character |
\s |
The name of the shell program |
\ t |
Current time (24-hour format), in hours: minutes: seconds |
\ t |
Current time (12-hour system) |
\@ |
Current time (12-hour format am/pm) |
\a |
Current (24-hour system), in hours: minutes |
\u |
User name of the current user |
\v |
The shell version number |
\v |
Shell's version number and issue number |
\w |
Current working directory Name |
\w |
The last part of the current working directory name |
\! |
Historical number of the current command |
\# |
Number of commands entered in the current shell session |
\$ |
Output "$" under Non-administrator privileges. Output "#" under Administrator privileges |
\[ |
Flags the beginning of one or more non-printable character sequences. Used to check in nonprinting control characters so that they operate the terminal emulator in a certain way, such as moving the cursor or changing the color of the text |
\] |
Marks the end of a non-display character sequence |
(015) Linux custom prompt