How to modify a terminal prompt in Linux

Source: Internet
Author: User
In Linux, you must be clear about how to modify the terminal prompt for a Linux Terminal. Recently, we found that the absolute path indicated by the terminal is very long after entering a deep level of a folder directory, this makes people feel unaccustomed. here we will introduce how to modify the terminal prompt... in Linux, you must be clear about how to modify the terminal prompt Linux Terminal. Recently, we found that the absolute path indicated by the terminal is very long after entering a deep directory in a folder, this makes people feel unaccustomed. here we will introduce how to modify the terminal prompts, and introduce the prompt color by the way: introduction to variables of www.2cto.com PS1 PS1 is an environment variable of Linux end users. it is used to describe the settings of command line prompts. You can use the man bash command to view the bash manual, find the special characters supported by the variable, and the significance of these special characters: \ d: # represents the date, in the format of weekday month date, for example: "Mon Aug 1" \ H: # complete host name. \ H: # only the first name of the host. in the preceding example, the name is fc4 ,. 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. \: # The Display time is in the 24-hour format: HH: MM \ u: # account name of the current user \ v: # BASH version \ w: # complete working directory name. In the home directory ~ Instead of \ W: # use basename to get the working directory name. Therefore, only the last Directory is listed, the prompt is: #, and the normal user is: $ modify the terminal prompt www.2cto.com to view the default prompt settings $ echo $ PS1 \ [\ e] 0; \ u @ \ h: \ w \ a \] $ {debian_chroot: + ($ debian_chroot)} \ u @ \ h: \ w \ $ modify the default settings and add the following commands to the current logon user ~ /. Bashrc file, and then use source to make it take effect. if you do not understand it ~ /. The role of the bashrc file. for details, refer to the execution sequence of the. bash_profile. bashrc profile File. $ vi ~ /. Bashrc # add the following settings at the end of the file: export PS1 = "[\ u @ \ h \ W] \ $" $ source ~ /. Bashrc # set the effective color. in PS1, set the character sequence color in the format of [\ e [F; Bm]. "F" indicates the font color, with a serial number of 30 ~ 37; "B" indicates the background color, numbered 40 ~ 47. Next let's take a look at the color table: foreground background color ---------------------- 30 40 black 31 41 Red 32 42 green 33 43 yellow 34 44 Blue 35 45 purple red 36 46 blue 37 47 White effect control code: code meaning of www.2cto.com ----------------------- 0 OFF 1 highlighted 4 underline 5 blinking 7 reversed display 8 invisible modification prompt color example $ PS1 = "\ [\ e [32m \] ### # \ [\ e [1; 31m \] \ u @ \ [\ e [36m \] \ h \ w] \ $ \ [\ e [m \ "description: '\ [\ e [32m \]' is used to set '#\##' to green, #### The command '[\ e [31m \]' is displayed. Set '\ u @' to red and highlighted, multiple numbers must be separated by semicolons. \ U @ is the username of the current logon followed by a '@' symbol. '\ [\ E [36m \]' sets '\ h \ w' to blue, and \ h indicates the first host name. if the host name is centos6.lampbo.org, centos6 is displayed; \ w displays the complete absolute path. '\ $' Indicates the character. if it is root, the prompt is: #, and the normal user is: $. '\ [\ E [m \]' to disable the color settings. If you do not have this, your command prompt, including the output from the command prompt, is the same as the last color setting. To maintain the variables you just set during startup and logon, you need to add the PS1 settings to the. bashrc file in the user's home directory.

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.