How to change my Bash shell prompt
The environment variable “PS1” determines how the shell prompt should appear in Bash. You can find the current setting of PS1 as shown below.
[neo@techpulp ~]# echo $PS1 [\u@\h \W]\$ [neo@techpulp ~]#
Bash supports some pre-defined automatic variable substitutions in the prompt string PS1. For example in the above PS1, bash will automatically substitute current user name ($USER) in the place of “\u”. Similarly host name for “\h” and base name of current directory name for “\W”. In the above example tilde (~) means I am currently in my home directory which is “/home/neo“.
Let us try few examples now.
Like Windows Shell
[neo@techpulp ~]# export PS1="\w> " ~> cd /usr/share/doc /usr/share/doc>
Date in the prompt
/usr/share/doc> export PS1="(\d) [\W]$ " (Sun Nov 16) [doc]$
Time in the prompt
(Sun Nov 16) [doc]$ export PS1="[\@ \W]# " [03:32 AM doc]#
Here is the list automatic substitutions supported by Bash.
\a 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
\A 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 effective 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 could be used to embed a terminal con-
trol sequence into the prompt
\] end a sequence of non-printing characters

