How to Modify the Linux Command Prompt

Commonly used without color: export $PS1="[\u@\h \w]\$"

 

How to Modify the Linux Command Prompt

Linux modifies the environment variable PS1 (command line prompt), you can use vi to edit the /etc/profile file, and add at the end: export PS1='[u@h W]$ ', where u displays the current user account, h Displays the current host name, W displays the current path, and $ displays the '$' symbol
  W instead of w, the absolute path to the relative path can be converted.
  The following is a brief description of the meaning of the default special symbols in the environment:
  d : Represents date, format For weekday month date, for example: "Mon Aug 1"
  H : Full host name. For example: my machine name is: fc4.linux, then this name is fc4.linux
  h: only take the first name of the host, as in the above example, it is fc4, .linux is omitted
  t: the display time is in 24-hour format , such as: HH:MM:SS
  T: display time is 12 hours format
  A: display time is 24 hours format: HH:MM
  u: current user's account name
  v: BASH version information
  w: complete working directory name. The home directory will replace
  W with ~: use basename to obtain the name of the working directory, so only the last directory will be listed
  #: the first few commands issued
  $: prompt character, if it is root, the prompt is: #, for ordinary users It is: $
  but 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 colored prompt, where e[1;xxm and e[m are the parts that change the font color of the terminal, the former is to modify the color, and the latter is to return to normal display. But there will still be problems at this time. When entering the first line in the prompt, the carriage return and line feed are abnormal, resulting in a very confusing display. Therefore, in addition to this modification, it is necessary to escape all non-printing characters with a special bash. The sequences "[" and "]" are enclosed. These two sequences tell bash that the enclosed character doesn't take up any space on the line, which allows word wrapping to continue to work properly. The final version is as follows (to solve the problem of non-wrapping with color prompts):
  PS1=”[e[1;32m]u[e[m][e[1;33m]@[e[m][e[1; 35m]h[e[m]:w$ "
  Wherein, the color is expressed as: 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white.
  If you need to change the directory to display colors on the command line:
  1. Cp the /etc/DIR_COLORS file to ~/ and rename it to .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
Change the display color to something else.
  Similarly, other display effects (including background) can also be modified by referring to the instructions.
  In this way, you can customize the personalized display effect in the command line mode under linux.
  3. Log in again, and you can see the modified effect.

Author: Leo Chin

+

-

0987

1

2

3

4

5

6

7

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326583213&siteId=291194637