When we log on to the system, the bash program starts and reads a series of configuration scripts called startup files, which define the default environment shared by all users. This is followed by more startup files in our home directory that define our personal environment. The exact sequence depends on the type of shell session being started.
Login and Non-login Shells
A login shell session is one in which we are prompted for our username and password; for example, when you log in on a text console, or through SSH, or with su -, you get an login shell. A non-login shell session typically occurs when we launch a terminal session in the GUI; for example, when you log in in graphical mode (on an X display manager), then you start a shell in a terminal in an existing session (screen, X terminal, Emacs terminal buffer, a shell inside another, …), you get a non-login shell.
|/etc/profile||Login||A global configuration script that applies to all users.|
|~/.bash_profile||Login||A user's personal startup file. Can be used to extend or override settings in the global configuration script.|
|~/.bash_login||Login||If ~/.bash_profile is not found, bash attempts to read this script.|
|~/.profile||Login||If neither ~/.bash_profile nor ~/.bash_login is found, bash attempts to read this file.|
|/etc/bashrc||Non-login||A global configuration script that applies to all users.|
|~/.bashrc||Non-login||A user's personal startup file. Can be used to extend or override settings in the global configuration script.|
In addition to reading the startup files above, non-login shells inherit the environment from their parent process, usually a login shell.
less ./.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH
According to the above information (based on my CentOS 7), we can find that the ~/.bashrc file is probably the most important startup file from the ordinary user's point of view, since it is almost always read. Non-login shells read it by default, and most startup files for login shells are written in such a way as to read the ~/.bashrc file as well.