Introduction to the 1.Linux command-line prompt
As we all know, the Linux command line is the system administrator to manage the Linux important means, we manage the Linux, first face is the Linux command line prompt.
The prompt at the end of the Linux command line has two different symbols, "#" and "$", as follows:
[[ email protected] ~]# #<== This is the command line for the Super Admin root user.
[[email protected] ~]$ #<== This is the command line for normal user Oldboy.
which
1) # is a command-line end prompt that uses superuser root login , and the $ number is a command-line end prompt with a normal user login.
2) Superuser has all the rights to manage the system, the normal user's permissions are relatively small, only basic system information to view and other operations, unable to change the system configuration and management services.
3) command line prompt @ The preceding character represents the currently logged on user (available WhoAmI query), after the@ is the hostname (available hostname query), where the location is the path of the current user of the window. Example below :
[[ Email protected] ~]$ #<[email protected] Before the Oldboy for the current user, @ after the Oldboy is the hostname, here the ~ represents the current directory, that is, home directory.
4 The Linux command prompt is controlled by the PS1 environment variable. Examples are as follows:
[Email protected] ~]# set|grep PS1 #<== Note that PS1 is uppercase.
Here's ps1= ' [\[email protected]\h \w]\$ ', can be used in global configuration file /ETC/BASHRC or/etc/profile on demand configuration and tuning.
2 . PS1 Variable knowledge description
The prompt for the Linux System Bash command line is controlled by a system environment variable called PS1. PS1 corresponding knowledge is shown in table 1.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/95/D6/wKiom1kacQ6j-t4ZAABJ5dEUlaA675.png "title=" 12306.png "alt=" Wkiom1kacq6j-t4zaabj5deulaa675.png "/>
3
. helpful tips for prompt
here we go.
3.1
Change the Linux prompt
the color
Learning Linux and doing Linux operations are very stressful, big guys do not set the color change, adjust the mood, reduce operational pressure, second, you can also test environment prompt color and formal environment, so as not to mistakenly operate the formal environment.
in the variable PS1, the format of the character color is: \[\e[f; Bm\], where "F" is the font color, number is 30-37, "B" is the background color, number 40-47. The color table is as follows:
F (foreground) |
B (background) |
Color Description |
30 |
40 |
black &NBSP; |
31 |
41 |
red &NBSP; |
32 |
42 |
green |
33 |
43 |
yellow |
34 |
44 |
blue |
35 |
45 |
magenta |
36 |
46 |
cyan Blue |
37 |
47 |
White |
For example: Adjust the command line font to yellow, background, and large background color.
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/95/D6/wKioL1kacPrCZrshAAAqZ_IqSjI744.png "title=" 12307.png "alt=" Wkiol1kacprczrshaaaqz_iqsji744.png "/>
Core content Character part:ps1= ' [\[\e[33;40m\]\[email protected]\h \w]# '
What do you think? Isn't that good?
3.2 Let
the command prompt displays the system path to the face
When we manage Linux from the command line, we often switch between different paths, and by entering the PWD command we can know what the current path is.
in fact, in The system uses the bash command line to automatically display the user's current path, but by default this path is not fully displayed, the following example will lead the reader to configure the command line to display the full path of the current user directly.
[[email protected] ~]# echo $PS 1 #<== Print the PS1 value corresponding to the Super Administrator .
[\[email protected]\h \w]\$ #<== @ is a delimiter that is similar to the @ function in a mailbox address.
You can modify the value of the PS1 variable to allow the command line to display the full path:
[[email protected] ~]# ps1= ' [\[email protected]\h \w]\$ ' #<==\w lowercase w
[Email protected] ~]# cd/usr/local/
[[email protected] /usr/local]# #<== can see the full path already.
[[email protected] ~]# ps1= ' [\[email protected]\h \w]\$ ' #<== Change the default \w to \w (lowercase w), which is only temporarily valid.
[[email protected] ~]# cd/etc/sysconfig #<== Switch directory experiment.
[[email protected] /etc/sysconfig]# #<== can see the path is the full path.
The above method is only temporary, in order to make the PS1 variable permanent, you can use the following configuration method:
Edit the/ETC/BASHRC file to find a line that matches the following (approximately on line 36th) and change the uppercase W in the content to lowercase w to make the variable permanent. That is to say:
["$PS 1" = "\\s-\\v\\\$"] && ps1= "[\[email protected]\h \w]\\$"
Change to the following content, save and exit.
["$PS 1" = "\\s-\\v\\\$"] && ps1= "[\[email protected]\h \w]\\$"
Finally, log out, log back in the system, or execute SOURCE/ETC/BASHRC directly to make the modified information effective.
3.3 Let
command line display current time
The adjustment method is:ps1= ' [\[\e[33;40m\]\[email protected]\h \w \ t]# ', that is \ t just fine .
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/95/D6/wKiom1kacWOzCbaqAABrN8xZmEg075.png "title=" 12309.png "alt=" Wkiom1kacwozcbaqaabrn8xzmeg075.png "/>
This article is from the "Old Boys Linux Training" blog, make sure to keep this source http://oldboy.blog.51cto.com/2561410/1926142
"Veterans sharing" Linux command line terminal prompt a variety of practical tips!