By default, the shell prompt has displayed the hostname and current working directory.
It is composed of some variables called:
- PS1 – default value is \s-\v\$ .
- PS2 – default is >
- PS3 – is used as the prompt for the select command
- PS4 – default is + and value of this parameter is expanded a to indicate multiple levels of indirection
Prompt is control via a special shell variable.y default, shell prompt is displayed hostname and current working directory.
1 2 3 4 5 6 7 8 | [free-tutorials@user ~]$ echo $PS1 [free-tutorials@user \W]$ [free-tutorials@user ~]$ echo $PS2 > [free-tutorials@user ~]$ echo $PS3 [free-tutorials@user ~]$ echo $PS4 + |
Here’s how to set the default value:
1 | $ PS1="\\u@\h \\W]\\$" |
The result will be:
1 | [user@domeniu ~]$ |
You can export this with command export:
1 | export PS1='[\u@\h \W]\$ ' |
Here is a list of most of the options you can use for the BASH prompt with Linux.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | \a – A bell character \d – Date (day/month/date) \D{format} – Use this to call the system to respond with the current time \e – Escape character \h – Hostname (short) \H – Full hostname (domain name) \j – Number of jobs being managed by the shell \l – The basename of the shells terminal device \n – Newline \r – Carriage return \s – The name of the shell \t – Time (hour:minute:second) \@ – Time, 12-hour AM/PM \A – Time, 24-hour, without seconds \u – Current username \v – BASH version \V – Extra information about the BASH version \w – Current working directory ($HOME is represented by ~) \W – The basename of the working directory ($HOME is represented by ~) \! – Lists this command’s number in the history \# – This command’s command number \$ – Specifies whether the user is the root (#) or otherwise ($) \\ – Backslash \[ – Start a sequence of non-displayed characters (useful if you want to add a command or instruction set to the prompt) \] – Close or end a sequence of non-displayed characters |