In this tutorial, I will show you everything about shell files: where they are located, when they are executed and how to use them.

Note: ~ refers to the user’s ‘HOME’ folder (e.g.: /home/john).

Table of Contents



This file is executed whenever a new shell is started (new terminal).


Executed after a successful interactive login.


Executed when a login shell exits.


System-wide .bashrc file. Executed before ~/.bashrc.


Executed by the command interpreter after a successful login. The file is not read by Bash if ~/.bash_profile or ~/.bash_login exists.


System-wide .profile file. There is also the folder /etc/profile.d where you can add your scripts. Executed before ~/.profile.


  • SSH: when you successfully connect to a server, /etc/bash.bashrc, /etc/profile (and scripts inside /etc/profile.d), ~/.profile (or ~/.bash_profile) and ~/.bashrc are executed.
  • In-server graphical login (display manager): after logged in, /etc/profile (and scripts inside /etc/profile.d) and ~/.profile (or ~/.bash_profile) are executed.
  • In-server terminal login: same files as with SSH.

If you have any suggestion, feel free to contact me via social media or email.