A user's prompt is determined by the value of the shell variables PS1, PS2, PS3, PS4.
PS1 – The value of this parameter is expanded and used as the primary prompt string.
The default value for Bash is \s-\v\$ .
PS2 – The value of this parameter is expanded as with PS1 and used as the secondary
prompt string. The default value for Bash is >
PS3 – The value of this parameter is used as the prompt for the select command
PS4 – The value of this parameter is expanded as with PS1 and the value is printed
before each command bash displays during an execution trace.
Typically a user only customizes PS1.
Bash allows these variables to be customized by inserting one or more escaped special characters:
\a : ASCII bell character
\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 : Tne ASCII escape character
\h : The hostname up to the first ‘.’
\H : The full hostname
\j : The number of jobs currently managed by the shell
\l : The basename of the shell's terminal device name
\n : A newline
\s : The name of the shell
\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 current version of bash (e.g., 2.00)
\V : The current release of bash, version and patch level (e.g., 4.12.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 sequence of non-printing characters, which could be used to embed
a terminal control sequence into the prompt
\] : End sequence of non-printing characters
Example:
fpm@fpmurphy ~]$ PS1="[\d \t \u@\h:\w ] $ "
[Sun Jul 05 23:44:17 fpm@fpmurphy:~ ] $
To persist the custom prompt across a reboot or a logout, add the prompt to the users $HOME/.bashrc
, or to make it the default prompt for all users, add it to /etc/bashrc
or create an entry under /etc/bashrc.d
depending on your distribution.