What is bashrc? Meaning & How It Works
In this article
The short answer: .bashrc is a shell script that runs every time you start an interactive, non-login Bash session on Linux or macOS. It is where you put aliases, functions, environment variables, and other settings that should be available in every new terminal window. It is a real, standard file name — not slang — and it has been part of Bash since the early days of the shell.
Origin and Standard Status
The name .bashrc is a combination of “Bash” (the Bourne Again SHell) and “rc,” which stands for “run commands.” The .rc suffix has been used in Unix since at least the 1960s, appearing in MIT’s CTSS system and later in Unix’s /etc/rc scripts that handled system startup. In the case of .bashrc, the file is a per-user configuration script that is sourced (executed in the current shell) each time a new interactive shell starts.
It is a standard file name, not informal slang. The Bash manual explicitly documents it under “Bash Startup Files.” It is also not a command or a program; it is a plain text file that contains shell commands. The leading dot makes it hidden in directory listings, so you won’t see it with a plain ls — you need ls -a.
How .bashrc Works
When you open a terminal window on most Linux distributions, the terminal starts a Bash shell that is both interactive (you can type commands) and non-login (you are already logged in). Bash reads ~/.bashrc at the start of that shell and executes every line in it. That means any command you put there runs automatically in every new terminal.
Here is a simple example of what a typical .bashrc might contain:
# Aliases
alias ll='ls -alF'
alias gs='git status'
Environment variable
export EDITOR=nano
Custom prompt
PS1='\u@\h:\w$ '
When you save that file and open a new terminal, ll becomes a shortcut for ls -alF, the EDITOR variable is set for programs that use it, and your prompt shows your username, hostname, and current directory.
If you edit .bashrc while a terminal is already open, the changes do not take effect until you start a new terminal or run source ~/.bashrc (or . ~/.bashrc) to reload it manually.
How to Find and Edit Your .bashrc
Your personal .bashrc lives in your home directory: ~/.bashrc (which expands to something like /home/yourname/.bashrc). To view it, open a terminal and run:
ls -a ~— lists all files including hidden ones, so you can confirm it exists.cat ~/.bashrc— prints the contents to the terminal.nano ~/.bashrc— opens it in the Nano text editor for editing.
If the file does not exist, you can create it with touch ~/.bashrc or just open it in an editor and save it. Most Linux distributions include a default .bashrc with helpful aliases and settings, so you will likely see one already.
Common Uses and Examples
People use .bashrc for a wide variety of personalizations. Some of the most common include:
- Aliases: Shortcuts like
alias update='sudo apt update && sudo apt upgrade'. - Environment variables: Setting
PATH,JAVA_HOME, orPYTHONPATHso programs can find their dependencies. - Functions: Defining small shell functions, e.g.,
mkcd() { mkdir -p "$1" && cd "$1"; }to create and enter a directory in one step. - Prompt customization: Changing the appearance of the command prompt with
PS1. - Startup programs: Launching tools like
ssh-agentortmuxautomatically.
It is important to note that .bashrc is only read for interactive shells. If you run a script or a command with bash -c, the file is not sourced, so your aliases and functions will not be available in that context.
Common Problems and Misconceptions
One frequent misconception is that .bashrc is the same as .bash_profile or .profile. They are different. .bash_profile is read for login shells, which happen when you log in via SSH or on the text console. On macOS, every new terminal window runs a login shell by default, so .bash_profile is the file you need to edit there — not .bashrc. On Linux, terminal windows are usually non-login, so .bashrc is the right place.
Another common issue: if you put a command in .bashrc that produces output or errors, it will appear in every new terminal. For example, a stray echo or a typo in a function definition can clutter your terminal. Always test your edits in a separate shell before committing them.
If you ever want to temporarily skip reading .bashrc, you can start Bash with bash --norc. This is useful for troubleshooting whether a problem is caused by your configuration.
Safety and Best Practices
Editing .bashrc is safe as long as you are careful. Here are a few rules:
- Always back up the file before making major changes:
cp ~/.bashrc ~/.bashrc.bak. - Do not add commands that run indefinitely or that require user input, because they will block every new shell.
- Avoid adding
exitto the file — it will close your terminal immediately. - Be cautious with
PATHmodifications: a wrongPATHcan break basic commands. If that happens, you can use the full path to a command (e.g.,/usr/bin/clear) to fix it.
If you break your .bashrc, you can restore it from the backup or, on many systems, from the default file in /etc/skel/.bashrc. That default file is a good starting point for a fresh configuration.
Alternatives and Related Files
Depending on your shell and system, you might also encounter:
.bash_profile— used for login shells on Linux and macOS..profile— the generic POSIX shell startup file, read by Bash if.bash_profiledoes not exist..zshrc— the equivalent file for Zsh, the default shell on macOS since Catalina..config/fish/config.fish— the configuration file for the Fish shell.
If you switch to Zsh, your .bashrc will not be read. You will need to migrate your aliases and variables to .zshrc. Many users keep a shared file that they source from both, but that is a personal choice.
Frequently Asked Questions
Do I need to restart my computer after editing .bashrc?
No. The file is read every time a new interactive Bash shell starts, so you only need to open a new terminal or run source ~/.bashrc in the current one.
Why is my .bashrc not working?
Check if you are using a login shell (e.g., on macOS). If so, edit ~/.bash_profile instead, or add a line to that file that sources .bashrc. Also verify the file has the correct permissions (readable by you) and that there are no syntax errors — run bash -n ~/.bashrc to check for syntax issues.
Can I use .bashrc on Windows?
Yes, if you use Windows Subsystem for Linux (WSL) or Git Bash. In WSL, your home directory is separate from Windows, so the file is at ~/.bashrc inside the Linux environment. In Git Bash, the file is usually at C:\Users\YourName\.bashrc.
What is the difference between .bashrc and .bash_profile?
.bashrc runs for interactive non-login shells (like a terminal window on Linux). .bash_profile runs for login shells (like SSH or a macOS terminal). Many Linux distributions have .bash_profile source .bashrc so the same settings apply in both cases.
Is it safe to delete .bashrc?
Deleting it will not break your system, but you will lose all your custom aliases, functions, and environment variables. The shell will still work with default settings. You can recreate it from /etc/skel/.bashrc if needed.