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.
nano or vim.cp ~/.bashrc ~/.bashrc.backupThe .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.
nano or vim depending on your preference. For nano, run nano ~/.bashrc. For vim, run vim ~/.bashrc. The tilde (~) represents your home directory.Ctrl+X, then Y to confirm, then Enter to save. In vim, press Esc, type :wq and press Enter.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.
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.
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.
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$.
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.
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.
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting