19. Bash Shell - Command Prompt Settings Customization
Contents
Command Prompt Overview
The command prompt looks like the following:
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:
|
|
set Command
|
|
Command Prompt Settings Modification
Temporarily Back Up the Original Settings
Let’s temporarily back up the current command prompt settings:
|
|
Set Command Prompt to Show Nothing
|
|
Let’s check if the command-line prompt can still working properly:
|
|
Set a Beep Sound
Every time the line breaks, the computer will make a sound:
|
|
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 Date in Customized Format
We can use the special character \D{format} to display customized date format at the command line prompt:
|
|
ps1_h_first_part
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 the Whole Hostname
We can use the special character \H to display the whole hostname at the command line prompt:
|
|
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 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 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 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:
|
|
We can use \A to show time without the second part:
|
|
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 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 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 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 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 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 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 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 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 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 a Backslash
We can use the special character \ to display a backslash at the command line prompt:
|
|
Restore from Backup
We can restore the setting from the PS1_BAK variable we created early:
|
|
Mimic the Default Settings
We can mimic the default setting:
|
|
References 6.9 Controlling the Prompt
Author Dong Chen
LastMod Wed Feb 20 2019