# How to decorate your Linux Terminal using Shell?

LinuxOperating SystemUbuntu

The Linux GUI based terminal window has many colours and font settings which can be enhanced as per the user choice. All these can be done using the shell commands and not just by clicking mouse buttons in the GUI component settings.

Most of these settings are handled through variables whose value can be changed or assigned by commands. In this article we will see how to handle the terminal prompt settings in Ubuntu based systems.

## The PS1 Variable

It is a environment variable which controls the primary prompt string which is displayed when the shell is ready to read a command. There are many backslash-escaped special characters whose value decide the display that will come out at the prompt. Let’s first see the value of the current prompt.

$echo$PS1

Running the above code gives us the following result −

$\e]0;\u@\h: \w\a$


The above format describes the different arguments that decide what is displayed at the PS1 prompt. Below is example of some of the such arguments which are most widely used in setting up the environment prompt.

•  \u: the username of the current user.

•  \h: the hostname up to the first dot (.) in the Fully-Qualified Domain Name.

•  \W:the basename of the current working directory, with $HOME abbreviated with a tilde (~). • \$: If the current user is root, display #, \$ otherwise.

## Customizing the PS1 Prompt

The PS1 promopt has features to assign various colours to the values like hostname, username etc. The below commands show an example of how they are applied. We use the \e special character at the beginning and an m at the end to indicate that what follows is a color sequence.

We can customize the following three aspects of the prompt.

Text Settings

ValueMeaning
0Normal Text
1Bold Text
4Underlined Text

Text Colours

ValueMeaning
30Black
31Red
32Green
33Yellow
34Blue

Background Colour

ValueMeaning
40Black
41Red
42Green
43Yellow
44Blue

But all these customizations are temporary. As soon as the user comes out of the terminal, these customizations are lost. To set them permanently, we need to add these to the. bashrc profile of the user.

Published on 14-Feb-2020 15:07:47