Linux terminal prompt PS1 settings (color)

Source: Internet
Author: User

/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 12 hours.
/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: $

In centos:
/A an ASCII Bell character (07)
/D the date in "weekday month date" format (e.g., "Tue may
26 ")
/D {format} The format is passed to strftime (3) and the result is
Inserted into the prompt string; an empty format results in
Locale-specific time representation. The braces are required
/E an ASCII escape character (033)
/H the hostname up to the First '.'
/H the hostname
/J the number of jobs currently managed by the Shell
/L the basename of the shell's terminal device name
/N newline
/R carriage return
/S the name of the shell, the basename of $0 (the portion
Following the final slash)
/T the current time in 24-hour hh: mm: SS format
/T the current time in 12-hour hh: mm: SS format
// @ The current time in 12-hour AM/PM format
/A the current time in 24-hour hh: Mm format
/U the username of the current user
/V the version of bash (e.g., 2.00)
/V the release of bash, version + patch level (e.g., 2.00.0)
/W the current working directory, with $ home abbreviated with a Tilde
/W the basename of the current working directory, with $ home abbreviated with a Tilde
/! The history number of this command
/# The command number of this command
/$ If the specified tive uid is 0, a #, otherwise a $
/NNN the character corresponding to the octal number NNN
// A backslash

/[Begin a sequence of non-printing
Characters, which cocould be used to embed a terminal control sequence
Into the prompt
/] End a sequence of non-printing characters

Therefore, you can specify your preferred command prompt format based on these settings:

PS1 = "/u @/h:/W/$"

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; 32 m/u/E [m/E [1; 33m @/E [m/E [1; 35 m/h/E [M: /W/$"


At this point, the display in the terminal should be a color prompt, where/E [1; xxm and/E [m is the part that changes the terminal font color, the former is to change the color, the latter is restored to normal display. However
At this time, there will be problems. 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 use a dedicated bash for all non-print characters
Escape Sequence "/[" and. These two sequences notify bash that the enclosed characters do not occupy any space on the row.
In this way, 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/$"

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.