During a user’s login process, when the bash shell starts, it executes some scripts to set the profile. These scripts can be customized and different in each Linux distribution. Its function is to configure some environment variables and tune the system for users.
To adjust the User Profile on Linux, bash reads the configuration from several files. The content of these files may vary from distribution to distribution, and a distribution does not always use them all, but the general idea remains.
Bash also searches for the /etc/bash.bashrc file, which also has a function similar to profile, but bashrc is executed every time bash is executed.
Each user can also create their own startup scripts to be executed during login. These files must be located in the users’ home directory with the names:
The dot “.” before the file name gives it the hidden attribute and is only listed with the command “ls —lga”.
Bash allows functions, variables, and nicknames to be written to some files so that they can be loaded again when the system is restarted, or a new bash execution takes place.
The files read by bash are:
Global Profile configuration file for all users. Defines global variables and is executed during the user authentication process. This script also usually loads the files contained in the /etc/profile.d directory with the source command.
This directory contains one or more scripts that are loaded by /etc/profile.
$ ls -l /etc/profile.d -rw-r--r-- 1 root root 1606 Jul 31 2018 colorls.sh -rw-r--r-- 1 root root 2703 Aug 2 2018 lang.sh -rw-r--r-- 1 root root 121 Jul 31 2018 less.sh -rw-r--r-- 1 root root 248 Jul 17 14:46 vim.sh
Global Profile configuration file, which defines important variables and runs every time Bash is loaded. In some distributions it appears under the name /etc/bashrc and in others as /etc/bash.bashrc.
Individual profile file for each user that is immediately executed at /etc/profile. Its content is read with each execution of Bash and each user has their own in the HOME directory.
If the file ~/.bash_profile does not exist, it is executed immediately after the login process. Each user has their own;
If the .bash_profile and .bash_login files don’t exist, it runs immediately after login. Each user has their own;
It runs automatically when the Bash process is started. Each user has their own;
It is executed during the logout process;
Remember that the “~/” indicates the HOME directory of the logged in user.
You might want to look at these files and analyze their content. Each distribution may; vary the content of these scripts. You might even notice that one script calls the other.
It is very important to know the function and when each file is executed. In general, keep in mind that:
Another important detail is that these files are read and executed in the order described above: first Profiles, then Bash. Not all distributions make use of all of these files.
The default order of the loading process of these scripts:
The ~/.bashrc script is loaded every time bash is executed. And the ~/.bash_logout script every time Bash terminates.
It’s common in some distributions missing some profile files. Each distribution adopts variations of this default profile schema.
The sudo command on Linux executes a given command as if it were another user.…
The ss command on Linux is extremely useful for investigating sockets, providing various information about…
Free Linux command shows the amount of total memory in use and available, as well…
The shell has structures for testing conditions and executing certain program sequences several times (loop),…
The /etc/fstab file stores the configuration of which devices should be mounted and what is…
The Netcat Command in Linux or nc is a utility used to do “almost anything”…
This website uses cookies.