19. Bash Shell - Command Prompt Settings Customization
Contents
Command Prompt Overview
The command prompt looks like the following:

Command prompt
View Settings of Current Command Prompt
There are several ways we can view the settings for the command prompt.
$PS1 Variable
We can get the command-line prompt setting by printing the environment variable $PS1:
|
|

Command prompt
set Command
|
|

Command prompt
Command Prompt Settings Modification
Temporarily Back Up the Original Settings
Let’s temporarily back up the current command prompt settings:
|
|

Temporarily back up current command prompt's settings

Check the temporarily backed up command prompt's settings
Set Command Prompt to Show Nothing
|
|

Empty the command prompt settings
Let’s check if the command-line prompt can still working properly:
|
|

The command prompt is still working
Set a Beep Sound
Every time the line breaks, the computer will make a sound:
|
|

Set a beep sound. We can use PS1= to reset the settings
Show Date in Week, Month, Date
We can use the special character \d to display weeks, months, and date at the command line prompt:
|
|

Show Week, Month, Date. We can use PS1= to reset the settings
Show Date in Customized Format
We can use the special character \D{format} to display customized date format at the command line prompt:
|
|
Show customized date format. We can use PS1= to reset the settings
Show Hostname Content Before the First Dot
We can use the special character \h to display the content before the first dot of the hostname at the command line prompt:
|
|

Show first part of the host. We can use PS1= to reset the settings
Show the Whole Hostname
We can use the special character \H to display the whole hostname at the command line prompt:
|
|

Show the whole hostname. We can use PS1= to reset the settings
Show the Number of Jobs Managed By Shell
We can use the special character \j to display the number of jobs managed by shell at the command line prompt:
|
|

Show the number of shell managed jobs. We can use PS1= to reset the settings
Show an Extra Line When Line Breaks
We can use the special character \n to display the an extra line at the command line prompt:
|
|

Show an extra line. We can use PS1= to reset the settings
Show the Name of the Shell
We can use the special character \s to display the name of the shell at the command line prompt:
|
|

Show the shell's name. We can use PS1= to reset the settings
Show the Time in Twenty-Four Hour Format
We can use the special character \t to display the time in 24-hour format at the command line prompt:
|
|

Show the 24-hour format time. We can use PS1= to reset the settings
We can use \A to show time without the second part:
|
|

Show the 24-hour format time without second part. We can use PS1= to reset the settings
Show the Time in Twelve Hour Format
We can use the special character \T to display the time in 12-hour format at the command line prompt:
|
|

Show the 12-hour format time. We can use PS1= to reset the settings
Show the Time in Twelve Hour AM/PM Format
We can use the special character \@ to display the time in 12-hour am/pm format at the command line prompt:
|
|

Show the 12-hour am/pm format time. We can use PS1= to reset the settings
Show the Name of the Current User
We can use the special character \u to display the name of the current user at the command line prompt:
|
|

Show the current user's name. We can use PS1= to reset the settings
Show the Version of the Bash
We can use the special character \v to display the version of the bash at the command line prompt:
|
|

Show the bash's version. We can use PS1= to reset the settings
Show the Release of the Bash
We can use the special character \V to display the release (version and patch level) of the bash at the command line prompt:
|
|

Show the bash's version and patch level. We can use PS1= to reset the settings
Show the Whole Current Working Directory
We can use the special character \w to display the whole path of current working directory at the command line prompt:
|
|

Show the whole working directory path. We can use PS1= to reset the settings
Show Only the Current Working Directory
We can use the special character \W to display the whole path of current working directory at the command line prompt:
|
|

Show only the current working directory. We can use PS1= to reset the settings
Show the History Number of the Command
We can use the special character ! to display the history number of the command at the command line prompt:
|
|

Show the command's history number. We can use PS1= to reset the settings
Show the Command Number of the Command
We can use the special character # to display the command number of the command at the command line prompt:
|
|

Show the command's command number. We can use PS1= to reset the settings
Show the Identity of a User
We can use the special character \$ to display the identity of a user at the command line prompt:
|
|
If the user’s uid equals to 0 then show #, otherwise show $:

Show the user's identity. We can use PS1= to reset the settings
Show a Backslash
We can use the special character \ to display a backslash at the command line prompt:
|
|

Show a backslash. We can use PS1= to reset the settings
Restore from Backup
We can restore the setting from the PS1_BAK variable we created early:
|
|

Restore settings from the backup. We can use PS1= to reset the settings
Mimic the Default Settings
We can mimic the default setting:
|
|

Mimic the default settings. We can use PS1= to reset the settings
References 6.9 Controlling the Prompt
Author Dong Chen
LastMod Wed Feb 20 2019