Difference Between .bashrc, .profile, .bash_profile, …?

By Xah Lee. Date: . Last updated: .

~/.bash_profile is loaded when you login. It is read only once.

~/.bashrc is loaded everytime you start a shell (For example, starting a terminal), but is not loaded when you login the first time.

Note: Some terminals (such as gnome-terminal) have option to “run command as login shell”, meaning, if on, it'll load ~/.bash_profile (or ~/.profile) first, before running ~/.bashrc.

Note: on Mac OS X, the Terminal app starts as a login shell, so it runs ~/.bash_profile. Different unixes have different setup.

Here's a excerpt from man bash:

     The systemwide initialization file, executed for login
     The  personal initialization file, executed for login
     The individual per-interactive-shell startup file
     The individual login shell cleanup file, executed when
     a login shell exits
     Individual readline initialization file

There's also {.login, .profile, …}. These are basically legacy that bash may also read.

Linux Terminal Topic

  1. Linux: Bash Keys, Terminal Keys, Man Page Keys
  2. Linux: Bash Prompt Setup
  3. Difference Between .bashrc, .profile, .bash_profile, …?
  4. Linux: How to use Virtual Console
  5. Linux: Terminal Control Sequence Keys
  6. Linux: Reset Terminal, Clear Screen History
  7. Linux: tmux Tutorial

  1. Linux: man page: text output, reading non-compressed man page, reading unformatted man page
  2. Linux: Bash Manual in Chapters, Using Emacs for Info
  3. Linux: BASH Shell Misc Tips
  4. Linux: Record a Terminal Session, Logging Shell Output

If you have a question, put $5 at patreon and message me.