What are the differences between .bash_profile vs .bashrc?

.bash_profile

.bash_profile is a file that is mainly located in user home directory and executed in case of login shell. When we open a terminal the .bash_profile file is executed.

.bashrc

.bashrc file is used and executed in case of non logged in shell. Let’s say we have a terminal open and if we now want to a separate tab then the .bashrc file is executed.

On OS X, Terminal by default runs a login shell every time, so this is a little different to most other systems, but you can configure that in the preferences.

However, if you add the following to your .bash_profile, you can then move everything into your .bashrc file so as to consolidate everything into one place instead of two:

if [ -f $HOME/.bashrc ]; then
        source $HOME/.bashrc
fi
Share