>[!quote] In a Nutshell
>In [[- Linux -|Linux]] and other Unix-like operating systems, the `~/.bashrc` and `~/.bash_profile` scripts are configuration files for the Bash shell. These files allow users to customize their shell environment, including aliases, functions, environment variables, and more.
---
#### Contents
- [[The PATH Variable]]
- [[PYTHONPATH]]
- Initialization script for [[Conda and Pip for Python|Conda]]
-
---
### **Differences between bashrc and bash_profile**
Both are configuration files, used in slightly different scenarios.
| Feature | `~/.bash_profile` | `~/.bashrc` |
| --------------------- | ---------------------------------------------- | ----------------------------------------------------------------- |
| **Usage** | Login shell configuration. | Non-login shell configuration. |
| **Execution Timing** | Runs once per session after login. | Runs every time a new shell starts. |
| **Focus** | Environment variables and PATH. | Aliases, functions, and prompts. |
| **Execution Context** | Non-login shell, e.g. when opening a terminal. | Login shell, e.g. when using accessing a system remotely via SSH. |
- **Source `~/.bashrc` from `~/.bash_profile`:** It’s common to include `~/.bashrc` inside `~/.bash_profile` to ensure that non-login shell configurations are available in login shells as well. This avoids duplicating configurations.
- Modern Linux systems often use `~/.bash_profile` only to source `~/.bashrc` because graphical terminals (non-login shells) are the most commonly used.
- Alternative files like `~/.profile` or `/etc/bashrc` may also be used depending on the distribution or global settings.
##### Example bash_profile
```bash
# ~/.bash_profile
export PATH=$HOME/bin:$PATH
export EDITOR=vim
# Source ~/.bashrc to include its settings
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
```
##### Example bashrc
```bash
# ~/.bashrc
alias ll='ls -la'
alias gs='git status'
# Set a fancy command prompt
PS1='\u@\h:\w\$ '
# Shell functions
function mkcd() {
mkdir -p "$1" && cd "$1"
}
```