Linux Bashrc File and Usage Examples

[rps-include post=6835]

Linux and related distributions like Ubuntu, Debian, CentOS, Fedora, RedHat, … provides shell to manage systems. By default bash shell is used by the most of the distributions. Every shell in Linux have some configuration, environment variables, etc. We generally need to change them after opening a new shell. .bashrc is used to set shell related configuration during new shell creation. In every new shell .bashrc file is fired before we get the new shell. In this tutorial we will look how to use .bashrc .

Edit .bashrc

.bashrc provides very flexible way to edit new shell configuration. Each user will have the .bashrc file in their home directory. .bashrc is a hidden file and not listed with ls or File managers. But we can edit it just providing the path like below.

Following command will open .bashrc of current user with nano text editor

$ nano ~/.bashrc

Which will look like below.

Edit .bashrc
Edit .bashrc

Add New Path Variable

One of the most popular use case for add new Path for the current user is adding to the .bashrc . In this example we will add path /opt/bin/ as new path for the current user.

export PATH=$PATH:/opt/bin

Add Alias

While running complex commands writing them again and again is redundant task. Alias can be used to create shortcuts in the command line. Another useful usage for .bashrc is defining new alias for the current user. In this example we add alias for mv  command.

alias mv='mv -i'

Change Prompt

Linux provides prompt for each interactive shell. This generally provides the user name , host name and path. We may want to use more simple prompt just like $ we can set from .bashrc with the following command.

export PS1="$ "

Source Other Configuration File

We may need to load other configuration and shell startup file other than .bashrc. In this situations we can use .bashrc too.

if [ -f /etc/bashrc ]; then 
        . /etc/bashrc 

Bashrc vs Bash_profile

There is an alternative to bashrc file which is named bash_profile . bash_profile provides global configuration for all users. Bashrc is limited with current user.

LEARN MORE  How To Set, Get and Change Bash Environment Variable?

Reload Bashrc

Sometimes we need to reload bashrc file without logout and login. We can use source mechanism to reload bashrc. One of the following commands can be used to reload bashrc.

$ source ~/.bashrc


$ . ~/.bashrc

[rps-include post=6835]

1 thought on “Linux Bashrc File and Usage Examples”

Leave a Comment