Edit “bashrc” on Linux for Color Prompt

The bashrc file in Linux is a configuration file containing configurations related to the system’s terminal. This file is executed whenever you log into your Linux system. By making different changes to this file, you can easily customize your Linux terminal within seconds. This includes changing the color of the prompt, playing around with the fonts, changing the user names that appear on the terminal, etc. For this particular discussion, we are interested in finding out the method of editing the bashrc file for changing the color of the prompt in a Ubuntu 20.04 system.

Method of Editing “bashrc” for Changing the Color of the Prompt in Ubuntu 20.04:

Along with offering multiple other terminal customization options, the bashrc file in Linux can also be edited to change the prompt’s color. For learning the method of doing so, you will have to go through the subsequent steps. However, we would like to mention beforehand that in this method, we will first teach you how to create a backup of the default settings so that you can always restore them whenever you want. After that, we will share with you the method of changing the color of the prompt, and for that, we have shared quite a few examples so that you can see how the prompt will look like after changing its colors. Finally, we have taught you the method of restoring the default prompt color in Ubuntu 20.04. So now, let us get started with the following steps:

Step # 1: View the “bashrc” File on your Ubuntu 20.04 System:

The bashrc file can easily be viewed on a Ubuntu 20.04 system by using any text editor of your choice. Here, we are going to use the nano editor for this purpose, and we will open the bashrc file with the help of the command shown below:

$ nano ~/.bashrc

The bashrc file of our Ubuntu 20.04 system is shown in the following image:

In this file, the section in which the attributes of the variable PS1 are defined is important for us. Basically, this variable allows you to customize your terminal in several different ways, along with changing the color of the prompt, which we will learn later in this article.

Step # 2: Take a Backup of the Relevant Variable of this File:

Now, for changing the color of the prompt in Ubuntu 20.04, we will be making some changes to the PS1 variable. However, before doing so, it is highly recommended that you take a backup of that variable so that if you mess up with anything during this whole process or even if you just want to go back to the default prompt color, you will easily be able to do that. For that, we will be copying the value of the PS1 variable to another variable. You can assign any name of your choice to this variable. The command shown below will serve this purpose:

$ TEMP=$PS1

This command will simply assign the default value of the PS1 variable to the TEMP variable, from where it can be restored later. This command will not generate any output upon successful execution.

Step # 3: Change the Color of your Ubuntu 20.04 Prompt from Green to Red:

Now, when we have taken a backup of our PS1 variable, we can easily change it to change the color of our Ubuntu 20.04 prompt. The default color of our Ubuntu 20.04 prompt is green. In this step, we will simply attempt to change this color to red. For that, we will execute the below-appended command:

$ PS1=“\[\033[31m\]\u@\h:\w$”

Running this command in the Ubuntu 20.04 terminal will also reflect these changes in your bashrc file.

As soon as you hit the Enter key for running the command as mentioned above, you will notice the color of your system’s prompt changing from green to red, as shown in the image below:

Step # 4: Change the Color of your Ubuntu 20.04 Prompt from Red to Blue:

You have seen how you can change the color of your Ubuntu 20.04 system’s prompt from green to red. Now, you will see how you can change it from red to blue. For that, you will have to run the affixed command in your terminal:

$ PS1=“\[\033[34m\]\u@\h:\w$”

Running this command in the Ubuntu 20.04 terminal will also reflect these changes in your bashrc file.

As soon as you hit the Enter key for running the command as mentioned above, you will notice the color of your system’s prompt changing from red to blue, as shown in the image below:

Step # 5: Change the Color of your Ubuntu 20.04 Prompt from Blue to White:

By now, you would have learned how to change the color of your Ubuntu 20.04 system’s prompt from green to red and red to blue. Now, you will see how you can change it from blue to white. For that, you will have to run the below-cited command in your terminal:

$ PS1=“\[\033[37m\]\u@\h:\w$”

Running this command in the Ubuntu 20.04 terminal will also reflect these changes in your bashrc file.

As soon as you hit the Enter key for running the command as mentioned above, you will notice the color of your system’s prompt changing from blue to white, as shown in the image below:

Step # 6: Restore the Original Color of your Ubuntu 20.04 Prompt:

In the same manner, you can change the color of your prompt by using other different color codes too. So now, we will teach you how to restore the original color of your Ubuntu 20.04 prompt. You remember we saved the default value of the PS1 variable of our bashrc file to a variable named TEMP at the beginning of this method. The sole purpose of doing so was to create a backup of the default value of the PS1 variable so that it can be restored later. For doing that, you simply need to execute the below-appended command in the terminal:

$ PS1=$TEMP

Running this command in the Ubuntu 20.04 terminal will also reflect these changes in your bashrc file.

As soon as you hit the Enter key for running the command as mentioned above, you will notice the color of your system’s prompt changing from white to its default color, i.e., green, as shown in the image below:

Conclusion:

This article explained to you in detail how you can easily change the color of your Ubuntu 20.04 system’s prompt simply by making some minor changes to your bashrc file. By following the very same method, you can also experiment with different colors. However, the only thing you need to be careful about is before proceeding with changing the color of your prompt, and you must take a backup of the relevant variable of your bashrc file. This is done to ensure that you do not lose any important configurations, and you can always go back to the default configurations whenever you feel like it.



from https://ift.tt/3DoqT8M

Post a Comment

0 Comments