How to modify a Linux Command Prompt
How to modify the Linux Command Prompt:
Modify the Linux Command Prompt to modify the Linux environment variable PS1. You can use VI to edit the/etc/profile file and add:
Export PS1 = '[\ U @ \ H \ W] \ $'
You can also edit it ~ /. Profile file (note the first line #/etc/profile ~ /. Profile)
Where \ U shows the current user account, \ h shows the current host name, \ W shows the current path, \ $ shows the '$' symbol
\ W can replace \ W to convert absolute paths to relative paths.
The following describes the meaning of the default special symbols in the environment:
\ 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 in the 12-hour format.
\ 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: $
Another question is, after modifying the. Profile/profile file, how can I apply the changes?
We can use the following command
source /etc/profile or source /etc/home/user/.profile
Change title
Prompt_command = 'echo-ne "/033] 0; $ {user }@$ {hostname }: ${PWD}/007 "'. In this way, the title at terminal will display the user @ machine name: path.
Change the color of the command prompt:
In ~ /. Add (green) to bashrc)
Export PS1 = "/[/033 [32 m/] [/W]/$/[/033 [0 m/]"
In/root/. bashrc :( red)
Export PS1 = "/[/E [31 m/] [/W] #/[/E [0 m/]"
Notice:
1./033 [32 M indicates that the subsequent characters must be green. /033 is also available for/E (0 m, indicating that default is used. 30 (black), 31 (red), 32 (green), 33 (yellow), 34 (blue), 35 (magenta), 36 (blue), 37 (white ).
2. For each color parameter,/[and/] Must be wrapped with two escape characters. This must be set at least on Ubuntu.
3./$ does not seem to work very well. When sudo reaches the root user, $ is still displayed, ideally #. So you can use $ directly without escaping/$
PS:
- /: 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 a 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
- /: 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