Change the prompt color by setting the PS1 variable in bash

Source: Internet
Author: User

Reference <prompt magic>

Ubuntu Initial bash prompt color is the same as the program output color, when a large number of output, it is often difficult to find out where the output information began. If you turn the color of the prompt into a more eye-catching color, it's easy to locate the output information at the beginning.
When you want to change the prompt color in bash, you can set it by the value of the PS1 variable, and if you put it in the. bashrc file in the user's corresponding directory, the user automatically changes the color when you open bash. Here, I change the prompt to green:
ps1= "\[\e[32m\]\[email protected]\h:\w\$ \[\e[0m]"
Here, the value between \e[and M is shaped like xx:xx, which indicates the foreground: background color. No background color refers to the system settings and is not specified separately. A value of 0 in \e[0m means that the initial value is restored, and the effect here is not to change the color of the user entering data after the prompt.
The characters between \[and \] Do not occupy space, which is required when there is too much input data (more than one line).
\u represents the user name
\h Host Name
\w current Directory
\$ user prompt, when root user becomes #
The remaining non-escaped characters are printed directly.

Change the prompt color by setting the PS1 variable in bash

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.