How to edit .bashrc on Linux

By Angus Published 25 February 2025 Updated 9 March 2026 4 min read

The .bashrc file configures your Bash shell environment. Every time you open a new terminal session, Bash reads this file and applies your custom settings. You can use it to create command shortcuts, set environment variables and define functions that automate repetitive tasks.

This guide shows you how to edit .bashrc and apply common customisations that improve your command-line workflow.

Before you begin

  • You need SSH access to your Linux server.
  • Basic familiarity with command-line text editors like nano or vim.
  • We recommend creating a backup of .bashrc before making changes: cp ~/.bashrc ~/.bashrc.backup

Open and edit .bashrc

The .bashrc file lives in your home directory. You edit it using a command-line text editor, make your changes and then reload the file to apply them.

  1. Open .bashrc in your text editor.
    Use nano or vim depending on your preference. For nano, run nano ~/.bashrc. For vim, run vim ~/.bashrc. The tilde (~) represents your home directory.
  2. Add your customisations.
    Scroll to the bottom of the file and add new lines for your aliases, functions or variables. Each customisation should be on its own line with correct Bash syntax.
  3. Save the file.
    In nano, press Ctrl+X, then Y to confirm, then Enter to save. In vim, press Esc, type :wq and press Enter.
  4. Reload .bashrc.
    Run source ~/.bashrc to apply your changes immediately. This reloads the file without closing your current terminal session.

Your customisations are now active. New terminal sessions will automatically load these settings.

Create command aliases

Aliases let you create shortcuts for frequently used commands. This reduces typing and speeds up common tasks.

Add these lines to .bashrc to create two useful aliases:

alias ll="ls -la"
alias update='sudo apt update && sudo apt upgrade'

The first alias creates an ll command that lists all files in long format with hidden files visible. The second creates an update command that updates your package list and upgrades installed packages in one step.

Set environment variables

Environment variables store values that programs can access. The PATH variable tells your shell where to find executable programs.

Add a directory to your PATH by including this line in .bashrc:

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

Replace /path/to/your/directory with the actual directory path. This appends your directory to the existing PATH, allowing you to run programs from that location without typing the full path.

Customise your command prompt

The PS1 variable controls how your command prompt appears. You can modify it to display different information or change its format.

Add this line to change your prompt to show username, hostname and current directory:

PS1="\u@\h:\w$ "

The escape sequences represent: \u for username, \h for hostname and \w for the current working directory. The result looks like username@hostname:~/directory$.

Define custom functions

Functions let you combine multiple commands into a single reusable command. This automates repetitive sequences.

Add this function to create and navigate into a new directory in one step:

mkdircd() {
  mkdir -p "$1"
  cd "$1"
}

After reloading .bashrc, run mkdircd new_folder to create a directory called new_folder and immediately change into it. The -p flag creates parent directories if needed.

Wrapping up

You now know how to edit .bashrc and apply customisations that improve your command-line efficiency. You created aliases for common commands, set environment variables, customised your prompt and defined functions that automate tasks.

Test your customisations by opening a new terminal session or running source ~/.bashrc. If something does not work as expected, check your syntax and refer to the Bash manual for detailed documentation. Our SSH connection guide covers accessing your server if you need help getting started.

Need more power?

Get scalable resources with our VPS hosting with root access and optional software.

Get VPS Hosting

Starting something new?

Perfect for websites and small businesses unlimited bandwidth with cPanel hosting.

Get cPanel Hosting