Linux Bashrc File and Usage Examples – POFTUT

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

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.

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.

LEARN MORE  What Is POSIX (Portable Operating System Interface) and It's Relation with Linux?

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.

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.

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.

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.

or

[rps-include post=6835]

1 Response

  1. 11/07/2017

    […] Linux Bashrc File and Usage Examples […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)