Linux Commands

How to Change the Color of Echo Output in Linux Terminal

The echo command in Linux is used to print something on the terminal. Usually, this command operates on the default terminal settings i.e. the format of its output is right in accordance with the current theme of your Linux terminal. However, you have the liberty to change the way the output of the echo command is displayed on your terminal. This guide will teach you the procedure of changing the color of the echo output from the regular Linux terminal theme.

How can I Change the Color of the Echo Command Output in the Linux Terminal:

It is very simple to change the color of the echo command output in the Linux Mint 21 terminal. There are two aspects of changing the output color: changing the foreground/ text color and changing the background color. Before heading on to these methods, we would like to show you the normal appearance of the echo command output so that you can compare it with the changed color later on. For printing a simple phrase on the terminal with the echo command, we will use the following command:

$ echo “Good Afternoon”

The image shown below displays the output of the echo command. You can see that the default text color in the output of the echo command is white whereas the background color is the same as the default color of the terminal is light grey. Now, we will change these colors by using the methods that follow.

Method # 1: Changing the Foreground/ Text Color

In this method, we will attempt to change the foreground/ text color of the echo command output from white to yellow. To do this, we will use the following command:

$ echo –e “\e[1;33mGood Afternoon\e[1;m”

Here, “33” refers to the color code of the yellow color for the foreground of the echo command output. The echo command has color codes for the foreground color ranging from 30 to 37. You can pick any color code of your choice from this range.

The image shown below displays the output of the echo command with a changed foreground color:

Method # 2: Changing the Background Color

Now, we will change the background color in the output of the echo command from grey to magenta. For that, we will use the following command:

$ echo –e “\e[1;45mGood Afternoon\e[1;m”

Here, “45” refers to the color code of the magenta color for the background of the echo command output. The echo command has color codes for the background color ranging from 40 to 47. You can pick any color code of your choice from this range.

The image shown below displays the output of the echo command with a changed background color:

Conclusion

By using the two methods discussed above, you can conveniently change the background and foreground/ text colors of the echo command output in your Linux terminal. Hence, you can make its output look all the catchier and more appealing.

Similar Posts