How to modify Linux Command Prompt

Source: Internet
Author: User
Tags printable characters

 

How to modify the Linux Command Prompt 14:01:23 www.hackbase.com Source: Internet
In Linux, you can modify the environment variable PS1 (command line prompt). You can use VI to edit the/etc/profile file and add: Export PS1 = '[U @ H w] $' at the end, U displays the current user account, H displays the current host name, W displays the current path, and $ displays the '$' symbol.
In Linux, you can modify the environment variable PS1 (command line prompt). You can use VI to edit the/etc/profile file and add: Export PS1 = '[U @ H w] $' at the end, U displays the current user account, H displays the current host name, W displays the current path, and $ displays the '$' symbol.
W can replace w to convert absolute paths to relative paths.
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 is used. For example, FC4 and. Linux are 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: $
However, the prompt displayed after this setting has no color. If you want to add a color setting, you can do this:
PS1 = "E [1; 32mue [me [1; 33m @ E [me [1; 35mhe [M: W $"
At this point, the display in the terminal should be a color prompt, where E [1; xxm and E [m are the parts that change the terminal font color, the former is to change the color, the latter is restored to normal display. However, there is still a problem. When you enter the first line in the prompt, the line break of the carriage return is not normal, resulting in confusion. Therefore, in addition to this modification, you also need to enclose all non-printable characters with a dedicated bash escape sequence "[" and. The two sequences notify bash that the enclosed characters do not occupy any space on the row, so that the automatic line feed can continue to work normally. The final version is as follows (this can solve the problem of no line break with a color prompt ):
PS1 = "[E [1; 32 m] U [E [m] [E [1; 33 m] @ [E [m] [E [1; 35 m] H [E [m]: W $"
Color: 30 = Black 31 = Red 32 = green 33 = yellow 34 = blue 35 = Magenta 36 = cyan 37 = white.
To change the color of the directory in the command line:
1. CP the/etc/dir_colors file ~ /, And renamed it. dir_colors.
2. Edit the. dir_colors file, find "dir 01; 34 # directory", and change 34 to 36.
You can find two lines of comments in the file:
# Text color codes:
#30 = Black 31 = Red 32 = green 33 = yellow 34 = blue 35 = Magenta 36 = cyan 37 = white
You can change the directory display color to another number based on the color.
You can also modify other display effects (including the background) by referring to the instructions.
In this way, you can customize your own Linux Command Line Mode for personalized display.
3. Log On again to see the modified effect.

This article from the network-China's largest network security site Source: http://www.hackbase.com/tech/2011-02-10/62516.html

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.