When a user logs into a Linux or Unix system, the system reads configuration files to determine how the session should be set up. There are several configuration files that can be used, and the specific file that is read depends on the type of login and the configuration of the system.
/etc/bashrc
The /etc/bashrc
file is a system-wide configuration file that is read by the Bash shell when it is started in interactive mode. This file is used to set system-wide environment variables and define default aliases and functions. It is not intended to be customized by individual users, and changes made to this file will affect all users on the system.
/etc/bash_profile
The /etc/bash_profile
file is another system-wide configuration file that is read by the Bash shell when a user logs in. This file is used to set environment variables and execute commands that should be run whenever a user logs in. Like /etc/bashrc
, it is not intended to be customized by individual users, and changes made to this file will affect all users on the system.
User Files
In contrast to the system-wide configuration files, the .bashrc
, .bash_profile
, .bash_login
, and .bash_logout
files are user-specific configuration files that are stored in the home directory of each user. These files are read by the Bash shell when a user logs in or logs out, or when a new interactive shell is started.
.bashrc
The .bashrc
file is read by the Bash shell when it is started in interactive mode, regardless of whether the user is logging in or starting a new shell. This file is used to set environment variables and define aliases and functions that should be available to the user whenever they are using the Bash shell.
.bash_profile
The .bash_profile
file is read by the Bash shell when a user logs in. This file is used to set environment variables and execute commands that should be run whenever the user logs in. If the .bash_profile
file does not exist, the Bash shell will look for a .bash_login
file. If neither of these files exists, the Bash shell will look for a `.profile` file.
.bash_login
The .bash_login
file is similar to the .bash_profile
file, but it is only read if the .bash_profile
file does not exist. It is used to set environment variables and execute commands that should be run whenever the user logs in.
.bash_logout
The .bash_logout
file is read by the Bash shell when a user logs out. This file is used to execute commands that should be run whenever the user logs out.
Summary
In summary, the /etc/bashrc
and /etc/bash_profile
files are system-wide configuration files that are read by the Bash shell when it is started in interactive mode or when a user logs in. The .bashrc
, .bash_profile
, .bash_login
, and .bash_logout
files are user-specific configuration files that are stored in the home directory of each user and are read by the Bash shell when a user logs in or logs out, or when a new interactive shell is started.