How to do it...

The terminal appearance is taken by the PS1 shell variable. The content allowed in PS1 will contain backslash-escape special characters.

First, we will see what PS1's current contents in the system. For that, run the following command:

$ echo $PS1

Here are the backslash-escape special characters:

  • \u: Current username
  • \h: Hostname
  • \W: Current working directory
  • \$: Will display # if the user is root; otherwise it will display $ only
  • \@: Current time in 12-hour AM/PM format

Now, we will modify our Bash. Run the following command:

$ PS1="[\\u@\\h \\W \\@]\\$"

Now, we will write a command to change the colors.

To make the text ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.