What is the .bashrc file and how can you configure it
November 22, 2024
.bashrc is a hidden text file in the home directory of a user on linux machines. It’s also known as the Bash running config file. Every time we start a new bash shell session, every command in the bashrc file is executed. If there is no .bashrc file which already present in your machine, then you can create one if you want and edit it using vim(or any other text editor of your choice).
You can do a lot of things with .bashrc to customise your own shell environment. For example, you could set your PS1 variable, which determines how your bash prompt looks. You can view your current PS1 variable by doing echo $PS1.
You can customize your PS1 variable and place it in bashrc to make sure that it gets shown every time you load a new shell.
Basically, I use .bashrc for persistence and you can do the same. In case I set an alias to another command in a terminal. Once I reload the terminal, that alias which I had set earlier would be lost.
But, in case I set this alias in bashrc, then this alias becomes persistent. Even on a new terminal, the alias would still be set, as every command in bashrc gets set before the terminal is shown to the user.
You can think of bashrc being like an automatic script which runs to configure your terminal environment, even before you can start using it.
I will edit this post when I get time, to write about uses of .bashrc in more detail.
In the future, I’ll also discuss about .vimrc too which is used to configure your vim environment.