How To Use Or What Is The Use Of .Bashrc File In Linux


Today lets learn about .bashrc file. If you have been using Linux for a while and particularly if you are beginning to get familiar with the Linux command line you will know that BASH is a Linux shell.

BASH stands for Bourne Again Shell. There are a number of different shells including csh, zsh, dash and korn.

A shell is an interpreter which can accept commands typed or entered by a user and run them to perform operations such as navigating around a file system, running programs and interacting with devices.

Many Debian based Linux distro’s such as Debian itself, Ubuntu and Linux Mint use DASH as a shell instead of BASH. DASH stands for Debian Almquist Shell. The DASH shell is very similar to BASH but it is a lot smaller than the BASH shell.

Regardless as to whether you are using BASH or DASH you will have a file called .bashrc. In fact you will have multiple .bashrc files.

Open a terminal window and type in the following command:

sudo find / -name .bashrc

When I run this command there are three results returned:

  • /etc/skel/.bashrc
  • /home/gary/.bashrc
  • /root/.bashrc

The /etc/skel/.bashrc file is copied into the home folder of any new users that are created on a system.

The /home/gary/.bashrc is the file used whenever the user gary opens a shell and the root file is used whenever root opens a shell.

What Is The .bashrc File ?

The .bashrc file is a shell script which is run every time a user opens a new shell.

For example open a terminal window and enter the following command:


Now within the same window enter this command:


Every time you open a terminal window the bashrc file is performed.

The .bashrc file is a good place therefore to run commands that you want to run every single time you open a shell.

As an example open the .bashrc file using nano as follows:

nano ~/.bashrc

At the end of the file enter the following command:

echo "Hello $USER"

Save the file by pressing CTRL and O and then exit nano by pressing CTRL and X.

Within the terminal window run the following command:


The word “Hello” should be appear along with the username you are logged in as.

Recommended for you: How To Backup Ubuntu Files And Folders And Restore

Use Of Aliases

The .bashrc file is commonly used to set aliases to commonly used commands so that you don’t have to remember long commands.

Some people consider this a bad thing because you could forget how to use the real command when placed on a machine where your own particular .bashrc file doesn’t exist.

The truth is however that all of the commands are readily available online and in the man pages so I see adding aliases as a positive rather than a negative.

If you look at the default .bashrc file in a distribution such as Ubuntu or Mint you will see some aliases already set up.

For example:

alias ll='ls -alF'

alias la='ls -A'

alias l='ls -CF'

The ls command is used to list the files and directories in the file system.

The -alF means that you will see a file listing show all files including hidden files which are preceded with a dot. The file listing will include the author’s name and each file type will be classified.

The -A switch simply lists all files and directories but it omits the .. file.

Finally the -CF lists entries by column along with their classification.

Now you could at any time enter any of these commands direct into a terminal:

ls -alF

ls -A


As an alias has been set in the .bashrc file you can simply run the alias as follows:




If you find yourself running a command regularly and it is a relatively long command it might be worth adding your own alias to the .bashrc file.

The format for alias is as follows:

alias new_command_name = command_to_run

Basically you specify the alias command and then give the alias a name. You then specify the command you wish to run after the equals sign.

For instance:

alias up='cd ..'

The above command lets you go up a directory simply by entering up.


The .bashrc file is a very powerful tool and is a great way to customize your Linux shell. Used in the correct way you will increase your productivity ten fold.

1 Comment

  • I recommend making §~/.bash_aliases§ where you put your personal §alias§es so that when §nano§ makes backups it doesn’t backup the whole §.bashrc§ which can get fairly massive.

    And §/etc/global_shell_aliases§ for global ones.

    Be sure to §source§ both first ! Add to §/etc/skel/.bashrc§ as well ! Like so:
    if [ -f /etc/global_shell_aliases ]; then
    . /etc/global_shell_aliases

    if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases

Leave a Comment