By default, the command line prompt displays the name of your computer and the name of the working directory. It also displays a dollar sign ($) to indicate that you are working as a user and not as the root user. If you work as root, the prompt displays a number sign (#). You can customize the prompt to display items, such as the current date or time, using prompt character codes. For example, PS1="\d \t \\:", displays the command line prompt as follows:
09:35:41 Thu Sep 9 \:
Make sure to include prompt character codes in quotes, otherwise, the prompt displays \t \d \\: instead of the time and date. The following table lists some prompt character codes you can use.
Prompt character code... |
Action... |
\$ |
displays a dollar sign ($), which indicates you are logged on as a user, or a number sign (#), which indicates you are working as the root user |
\\ |
displays a backslash (\) |
\d |
indicates current date, e.g., Thu Sep 9 |
\t |
indicates current time, e.g., 09:35:41 |
\s |
displays the current shell name |
\h |
indicates the name of the host computer running the shell |
\w |
indicates the absolute path name of your working directory |
To change the default command prompt
1. At the command line, type,
PS1="[<prompt character codes>]"
2. Press ENTER.
Notes
If you use multiple prompt character codes, include spaces between each code to facilitate readability.
Do not include the brackets, as they indicate that prompt character codes are optional. For information about notation conventions for commands, see " Using notation conventions for Linux commands."