.bashrc is a per-user startup script in the home directory that the Bash shell executes every time it starts an interactive non-login shell, such as a new terminal window on a Linux desktop. It holds the settings that shape daily command-line work: aliases, shell functions, the prompt, shell options and environment variables.
The name follows the Unix convention of rc files, short for run commands, and the leading dot makes the file hidden in ordinary directory listings. In the shell and terminal toolset of Linux, .bashrc is the first place administrators and developers look when a shell behaves differently from one account to another.
When Bash reads .bashrc
Bash decides which startup files to read based on two properties of the shell: whether it is a login shell and whether it is interactive. An interactive non-login shell reads ~/.bashrc directly. A login shell, such as an SSH session or a text console login, reads /etc/profile and then the first file found among ~/.bash_profile, ~/.bash_login and ~/.profile, and it does not read .bashrc on its own.
Because of this split, most distributions ship a default ~/.bash_profile or ~/.profile that sources .bashrc explicitly, so that login and non-login sessions share the same interactive settings. Non-interactive shells that run scripts read neither file, unless the BASH_ENV variable points to a file.
The table below shows which files each type of shell reads at startup.
| Shell type | Typical example | Files read |
|---|---|---|
| Interactive login | SSH session, console login | /etc/profile, then first of the profile files |
| Interactive non-login | New terminal tab on a desktop | System bashrc, then ~/.bashrc |
| Non-interactive | Running a shell script | File named in BASH_ENV, if set |
| Invoked as sh | Script with a POSIX shebang | /etc/profile and ~/.profile in login mode |
Many systems also have a system-wide file, /etc/bash.bashrc on Debian and Ubuntu or /etc/bashrc on Fedora and related distributions. The exact loading path differs by distribution, so the default skeleton files in /etc/skel are the reliable reference for a given system.
What belongs in .bashrc
.bashrc is meant for settings that only matter in an interactive session. Typical contents include shell aliases such as alias ll='ls -alF', small shell functions, the PS1 prompt definition, history settings such as HISTSIZE and HISTCONTROL, shell options set with shopt, and the loading of tab completion scripts.
The following table groups the common contents of .bashrc by purpose.
| Category | Example setting | Effect |
|---|---|---|
| Aliases | alias gs=’git status’ | Shortens frequent commands |
| Prompt | PS1 with user, host and directory | Shows context before each command |
| History | HISTSIZE=10000, histappend | Keeps more commands across sessions |
| Shell options | shopt -s globstar | Enables recursive directory globbing |
| Completion | Source bash-completion script | Adds context-aware tab completion |
| Functions | mkcd to create and enter a directory | Packages repeated steps |
A good default file starts with an interactivity guard such as [[ $- == *i* ]] || return. This line stops the file early when it is sourced by a non-interactive process, which prevents output from breaking tools like scp, rsync or remote command execution over SSH.
How .bashrc differs from other shell startup files
The central rule is that environment belongs in the profile and interactive behavior belongs in .bashrc. Environment variables such as PATH are inherited by child processes, so setting them once at login is enough, while aliases and functions are not inherited and must be redefined in every interactive shell.
The table compares .bashrc with the neighboring files that users most often confuse it with.
| File | Read by | Best used for |
|---|---|---|
| ~/.bashrc | Interactive non-login Bash | Aliases, prompt, functions, options |
| ~/.bash_profile | Login Bash only | Environment, then sourcing .bashrc |
| ~/.profile | Login shells, several shells | Shell-neutral environment variables |
| ~/.bash_logout | Login Bash on exit | Clearing the screen or temporary files |
| ~/.zshrc | Interactive Zsh | Zsh equivalent of .bashrc |
On macOS, Terminal historically opened every window as a login shell, so settings placed only in .bashrc seemed to be ignored. Current macOS versions use Zsh by default, which reads ~/.zshrc instead, so a user who switches shells must move or translate the configuration.
Applying and testing changes safely
Edits to .bashrc take effect only in shells started after the change. Running source ~/.bashrc or its short form . ~/.bashrc applies the file to the current session, although it does not remove aliases or variables that were deleted from the file.
Before editing, it is wise to keep a second terminal open or make a backup copy. A syntax error or an exit command placed in the wrong spot can make every new shell close immediately, and a sensible recovery is to start bash --norc and repair the file. Running bash -n ~/.bashrc checks syntax without executing anything.
For larger setups, many users split configuration into separate files, for example ~/.bashrc.d/aliases.sh, and source them in a loop. Keeping these files in a version-controlled dotfiles repository makes the same environment reproducible across servers and workstations.
Common mistakes with .bashrc
Most .bashrc problems come from putting settings in the wrong file or from commands that assume an interactive terminal. The table below lists frequent symptoms with their cause and fix.
| Symptom | Cause | Fix |
|---|---|---|
| Aliases missing over SSH | Profile does not source .bashrc | Source .bashrc from .bash_profile |
| scp or rsync fails | File prints text when non-interactive | Add the interactivity guard |
| PATH grows with duplicates | PATH appended in every nested shell | Set PATH in the profile instead |
| Slow terminal startup | Heavy commands run at every launch | Lazy-load tools or cache results |
| Every new shell exits | Syntax error or stray exit command | Repair from bash –norc |
A further risk is storing secrets such as API tokens in .bashrc. The file is often copied into public dotfiles repositories, so credentials belong in a separate file with restrictive permissions or in a dedicated secret manager.
In everyday language
The .bashrc file is like a personal checklist that the command line reads each time you open a new terminal window. It tells the shell how you like things set up. It saves your shortcuts, your preferred prompt and your habits, so you do not have to type them again every day.
Each person on a computer has their own copy. Changing it only affects your own sessions, and the changes appear the next time you open a terminal.
Seen in the real world
A site reliability engineer manages about 60 Linux servers and often works in several terminal tabs at once. She keeps a single .bashrc in a dotfiles repository and deploys it to every server with a configuration management tool.
The file sets HISTSIZE to 50,000 with timestamps, so she can reconstruct exactly which commands ran during an incident. It defines a prompt that shows the hostname in red on production machines and in green on staging, which sharply reduces the risk of running a command on the wrong server. An interactivity guard at the top keeps automated rsync backups working, and the same file sources a tab completion script for the cluster management tool her team uses.