Modify the Ubuntu terminal display directory and computer name)

Source: Internet
Author: User

Note:
Usage:
# PS1 = 'custom Content'

Note the single quotation marks on both sides.

Example: PS1 = '(\ [email protected] \ H \ D \ t) \ $'

Bytes ----------------------------------------------------------------------------------------------------------------

PS1: the user's usual prompt.
PS2: the first line is not complete. Wait for the prompt entered in the second line.

Linux system prompts are defined by the system variable ps1. The default format is [[email protected] working directory] $.
Use echo $ PS1 to obtain the PS1 value, that is, PS1 = "[\ [email protected] \ H \ W]" \ $
After logging on, you can change the display style of PS1. However, after you log on to the system from the left-side Navigation Pane and log on to the system, the style changes to the default style of the system. If you want to completely change the style of PS1, it can only be changed from the configuration file.
PS is defined in. bash_profile under the user root directory.

For example

#. Bash_profile

# Get the aliases and functions

If [-f ~ /. Bashrc]; then

.~ /. Bashrc

Fi

# User specific environment and startup programs

# The following are the set PS1 values.

PS1 = "[\ [email protected] \ 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

Unset Username

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 ~ /. Bahrc specifies the ratio. For example, my settings are as follows:
Configuration 1:
PS1 = "\ [\ e [32m \] [\ [email protected] \ H \ W] $ \ [\ e [M \]"
Export PS1
Effect:
[[Email protected] ~] $

Configuration 2:

If [$ term = 'linux ']; then
Export PS1 = "[\ [\ e [36; 1m \] \ [email protected] \ H \ [\ e [31; 1 Mbit/s \] \ W \ [\ e [32; 1 Mbit/s \]>"
Zhcon -- utf8
Clear
Elif [$ term = "xterm"]; then
Export PS1 = "[\ [\ e [31; 1m \] \ W \ e [0 m]>"
Fi

Modify the Ubuntu terminal display directory and computer name)

Related Article

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.