Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

What Is the .bashrc File in Linux?

The .bashrc file sets up your terminal every time you open it. Use it for shortcuts, functions and a custom prompt.

VPS and Cloud Servers2 min read3 steps7 screenshots

What it is

.bashrc is a script that Bash reads each time you open a new terminal. It lives in your home folder (~/.bashrc), and each user has their own copy. People use it for:

  • Aliases, which are short names for long commands
  • Functions, which bundle several commands
  • Environment variables, such as PATH
  • The prompt, the text you see before each command

Because it loads every time, your tools and settings look the same on every terminal and every login.

Open and edit the file

cd ~
nano ~/.bashrc
The .bashrc file in nano
  1. Add, change or remove lines.
  2. Save the file and leave the editor.
  3. Load the changes into your current terminal:
source ~/.bashrc

Add an alias

An alias is a shortcut. This one makes abc run ls -l:

alias abc='ls -l'
An alias in .bashrc

Reload the file and test it:

source ~/.bashrc
abc
Reloading .bashrc
The alias at work

Another useful alias updates the system in one word:

alias upgrade='sudo apt update && sudo apt upgrade'
Tip: Use a name that no other command uses. Otherwise the alias may hide the real command.

Add a function

This function makes a folder and moves into it:

mkdircd() {
    mkdir -p "$1"
    cd "$1"
}
A function in .bashrc

After you reload the file, run:

mkdircd test_dir
The mkdircd function at work

Set a variable

Add a folder to the PATH, so you can run its programs from anywhere:

export PATH=$PATH:/path/to/your/directory

Change the prompt

The PS1 variable controls the prompt. This example replaces the user and host name with a # sign:

PS1="# "
A custom prompt

Quick recap

  • ~/.bashrc runs for every new Bash session.
  • Edit it with nano, then run source ~/.bashrc.
  • Use it for aliases, functions, variables and the prompt.