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

Bash

~/.bashrc

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

~/.bash_profile

Executed after a successful interactive login.

~/.bash_logout

Executed when a login shell exits.

/etc/bash.bashrc

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

~/.profile

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

/etc/profile

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

Notes

  • 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.