Till now, we have seen different scripts, these scripts initialize the operating system, prior to the login of any user. Once the basic operating system in initialized, the user login process starts. This process is explained in the following topics.
In the /etc/ folder, the following files are related to the user level initialization:
/etc/profile: Few distributions will have additional folder /etc/profile.d/. All the scripts from the profile.d folder will be executed./etc/bash.bashrcThe preceding scripts are called by all the users, including root and normal users. Initially, the /etc/profile script will be called. This script creates system-wide environment settings. Few distributions will have the /etc/profile.d/ folder. SuSE Linux has additional /etc/profile.local script. The scripts in this folder will also be called. Then, the /etc/bash.bachrc script will be executed.
Scripts in the /etc/ folder will be called for all the users. Particular user-specific initialization scripts are located in the HOME folder of each user. These are as follows:
$HOME/.bash_profile: This contains user-specific bash environment default settings. This script is called during the login process.$HOME/.bash_login: This contains the second user environment initialization script called during login process.$HOME/.profile: If present, this script internally calls the .bashrc script file.$HOME/.bashrc: This is an interactive shell or terminal initialization script.All the preceding script's names start with dot. These are hidden files. We will need to give the ls -a command to view these files.
Whenever we create a new shell terminal, such as, if we pressed the Ctrl + Alt + T key combination or we start a terminal from the applications tab then the terminal which is created is called the interactive shell terminal. We use this terminal to interact with the operating system. This is not the login shell, which is created during the boot-up process. But this interactive shell terminal gives us the CLI prompt for entering the command to execute.
Whenever we create an interactive bash terminal, Shell scripts from /etc/profile and similar are not called, only the ~/.bashrc script is called every time we create a new interactive shell terminal. If we want any environment customization for every newly created interactive shell terminal, we need to customize the .bashrc script from the home folder of the user.
If you check the content of $HOME/.bashrc, you will observe the following:
.bashrc script is the setting promptless commandgrep, fgrep, egrep, ll, la, l, and similarIf we customize .bashrc such as adding new alias commands or declaring a new function or environment variables, then we should execute .bashrc to take its effect. The following are the two ways to run the .bashrc script so that the environment of the current shell will also be updated as per the customization done in the .bashrc script:
$ source .bashrc$ . bashrcIn these two techniques, the child shell is not created but the new function is. Environment and similar variables will become a part of the current shell environment.
Every user's home folder has one more script called .bash_logout. This script is called or executed when the user exits from the login shell.
If the system user is an embedded system developer, who is interested in adding or modifying the device's driver-related command, then he or she will have to make changes in the /etc/rc*.d folder scripts, or they may have to modify the /etc/rc.local script.
If the administrator wants to modify the environment for all the users, then they will have to modify the /etc/profile and /etc/bash_bashrc scripts.
If we want to customize the environment related to a particular user, then the scripts located in the user's home folder, such as $HOME/.profile, $HOME/bash_profile, and $HOME/bash_login scripts, should be modified.
If the user wants to customize only the interactive shell terminal environment, then they will have to customize the $HOME/.bashrc script.
If you are working in system administration, then I would suggest you learn about the /etc/fstab file and it's editing. This file is used for configuring mount points and how file systems are mounted.