System-wide setting scripts
/etc/profile: A few distributions will have an additional folder called
/etc/profile.d/. All the scripts from the
profile.dfolder will be executed.
The preceding scripts are called by every user, including root and normal users. Initially, the
/etc/profile script will be called. This script initializes system-wide environment settings. A few distributions will have the
/etc/profile.d/ folder. SUSE Linux has an additional
/etc/profile.local script. The scripts in this folder will also be called. Then, the
/etc/bash.bashrc script will be executed.
User level settings – default files
$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 the login process.
$HOME/.profile: If present, this script internally calls the
$HOME/.bashrc: This is an interactive shell or terminal initialization script.
All the preceding script names start with a dot. These are hidden files. We will need to give the
ls -a command to view these files.
- Non-login shells
Whenever we create a new shell Terminal, such as when we press the Ctrl + Alt + T key combination, or we start a Terminal from the applications tab, then the Terminal that 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 is an interactive shell Terminal that gives us the
CLI prompt for entering the commands 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. This happens every time we create a new interactive shell terminal. If we want 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:
.bashrcscript is setting the prompt
- It initializes the environmental variables,
- It customizes the output of the
- It creates various alias commands such as
l, and similar
If we customize
.bashrc, such as adding new alias commands or declaring a new function or environment variables, then we should execute
.bashrc for it to take effect. The following are 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
$ source .bashrc$ . .bashrc
Please note the usage of
.(dot) two occasions, the first time for the command
.(dot) and the second time in the script name, which we want to call.
With these two techniques, the child shell is not created but the
.bashrc script runs in the current shell environment. Therefore, all updated or newly created environment variables become 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, and is interested in adding or modifying the device’s driver-related commands, then they will have to make changes in the
/etc/rc*.d folder scripts, or they may have to modify the
If the administrator wants to modify the environment for all users, then they will have to modify the
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/bash_login scripts, should be modified.
If you are working in system administration, then I would suggest you learn about the
/etc/fstab file and its editing. This file is used for configuring mount points and how file systems are mounted.