Linux Terminal prompt color settings

Source: Internet
Author: User

Add the following statement to the. bashrc file in the user directory, and then execute the source. BASHRC to make it effective immediately.

Ps1= ' ${debian_chroot:+ ($debian _chroot)}\[\033[01;31m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[ 00m\]\$ '

List of identifiers:
< common >
\u: Current user's account name
\h: Only the first name of the host is taken, as in the example above, then Fc4,.linux is omitted
\h: The full host name. For example: My machine name is: Fc4.linux, then this name is Fc4.linux
\w: The full working directory name. Home directory will be replaced by ~
\w: Use basename to get the working directory name, so only the last directory is listed
\$: Prompt character, if root, Prompt is: #, normal user is: $

\#: The first few commands issued
\ n: Create a new row
\d: Represents the date, formatted as weekday month date, for example: "Mon-1″
\ t: Display time in 24-hour format such as: HH:MM:SS
\ t: Display time in 12-hour format
\a: Display time in 24-hour format: hh:mm
Version information for \v:bash

Escape sequence Character

In order to add a personal-style color prompt, we need to use escape sequence characters. An escape sequence character is a control command that controls the shell's execution of a particular action. an escape sequence character usually starts with ESC, is recorded as "^[" in the shell, and is sometimes recorded as 3 (because ESC is 27 in ASCII encoding and octal is recorded as 033). In order to enter an escape sequence character directly in the shell, it is generally preceded by "Ctrl + V", which is "Ctrl-v ESC".

Using the shell color

First use an example to illustrate how to implement the shell color:

Ps1= "[3[0;32;[ Email protected]:w$ 3[0m] "


The following prompt is displayed:


In the command above, "3[0;32;40m" indicates the color of the text behind it, "3" means start an escape sequence, "[" Defines the start color definition, "0" defines the default font color, and the rest of the section is defined later. "32" defines the foreground color of the text, where 32 means green; "40" Defines the background color of the text, and 40 indicates black. At the end of the string, "3[0m" is defined, and it is used to restore the default text color setting so that only a color prompt is obtained without affecting the command and the color display of its output (that is, white on black).

Color list:
Style

00-normal (no color, no bold)
01–bold

Text color

30-black
31-red
32-green
33-yellow
34-blue
35-magenta
36-cyan
37-white

Background color

40-black
41-red
42-green
43-yellow
44-blue
45-magenta
46-cyan
47–white

Linux Terminal prompt color settings

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.