How to Change Putty / Terminal Prompt in Linux
to change the prompt in linux putty / terminal, you should issue the below command in putty / terminal and press enter.
PS1='MyPrompt:\w> '
export PS1
to save the prompt, add the two lines to your $HOME/.bashrc on the server
prompt with working directory@username
PS1='\w@\u> '
prompt with hostname:working directory@username
PS1='\h:\w@\u> '
Option | Description |
---|---|
\d | displays date, in "Weekday Month Date" format (e.g., "Tue May 26"). |
\h | displays hostname, first word . (e.g. mymachine) in hostname |
\H | displays complete hostname |
\j | displays number of jobs currently managed by the shell. |
\l | displays basename of the shell's terminal device name. |
\s | displays name of the shell, the basename of $0 |
\t | displays time, in 24-hour HH:MM:SS format. |
\T | displays time, in 12-hour HH:MM:SS format. |
\@ | displays time, in 12-hour am/pm format. |
\u | displays username of the current user. |
\v | displays version of Bash (e.g., 2.00) |
\V | displays release of Bash, version + patchlevel |
\w | displays current working directory. |
\W | displays basename of $PWD. |
\! | displays history number of this command. |
\# | displays command number of this command. |
\$ | displays $ if user is not root otherwise it displays # |
\\ | displays backslash in prompt |
\[ | Begin a sequence of non-printing characters. |
\] | End a sequence of non-printing characters. |
PS1='\[\e[32m\]\u@\h:\w\[\e[0m\] '
the above prompt change the putty prompt color to Green
Code | Description | Example |
---|---|---|
30 | Dark Grey | PS1='\[\e[30m\]\u@\h:\w\[\e[0m\] ' |
31 | Red | PS1='\[\e[31m\]\u@\h:\w\[\e[0m\] ' |
32 | Green | PS1='\[\e[32m\]\u@\h:\w\[\e[0m\] ' |
33 | Yellow | PS1='\[\e[33m\]\u@\h:\w\[\e[0m\] ' |
34 | Blue | PS1='\[\e[34m\]\u@\h:\w\[\e[0m\] ' |
35 | Purple | PS1='\[\e[35m\]\u@\h:\w\[\e[0m\] ' |
36 | Turquoise | PS1='\[\e[36m\]\u@\h:\w\[\e[0m\] ' |
37 | Light Gray | PS1='\[\e[37m\]\u@\h:\w\[\e[0m\] ' |