Execution description of profile in Linux

Original link: http://www.linuxidc.com/Linux/2012-09/71389.htm

(1)/etc/profile

Global (public) configuration, which is read when logging in, regardless of the user.

(2)/ect/bashrc

Ubuntu does not have this file. The corresponding file is /ect/bash.bashrc, which is also global (public). When bash is executed, no matter what the method is, this file will be read.

(3)~/.profile

If bash is executed in login mode, read ~/.bash_profile, if it does not exist, read ~/.bash_login, if the first two do not exist, read ~/.profile.

Also, when logging in in graphical mode, this file will be read even if ~/.bash_profile and ~/.bash_login exist.

(4)~/.bash_login

If bash is executed in login mode, read ~/.bash_profile, if it does not exist, read ~/.bash_login, if the first two do not exist, read ~/.profile.

(5)~/.bash_profile

Unbutu does not have this file by default and can be created.

This file is only read when bash is executed as login. Usually this configuration file is also configured to read ~/.bashrc.

(6)~/.bashrc

This file is read when bash is executed in non-login form. If executed in login form, this file will not be read.

(7)~/.bash_logout

This file will only be read when logging out and in the form of longin. That is, when logging out in text mode, this file will be read, and when logging out in graphics mode, this file will not be read.

Here are a few examples on this machine:

1. When logging in in graphical mode, read sequentially: /etc/profile and ~/.profile

2. After logging in in graphical mode, when opening the terminal, read sequentially: /etc/bash.bashrc and ~/.bashrc

3. When logging in in text mode, read sequentially: /etc/bash.bashrc, /etc/profile and ~/.bash_profile

4. From other users su to this user, there are two cases:

(1) If the -l parameter (or - parameter, --login parameter) is used, such as: su -l username, then bash is lonin, and it will sequentially read the following configuration files: /etc/bash.bashrc, /etc /profile and ~/.bash_profile.

(2) If there is no -l parameter, bash is non-login, it will read sequentially: /etc/bash.bashrc and ~/.bashrc

5. When logging out, or logging out of the su user, if it is in the longin mode, then bash will read: ~/.bash_logout

6. When executing a custom shell file, if you use the "bash -l a.sh" method, bash will read the lines: /etc/profile and ~/.bash_profile, if you use other methods, such as: bash a. sh, ./a.sh, sh a.sh (this does not belong to the bash shell), it will not read any of the above files.

7. The above examples always read ~/.bash_profile. If the file does not exist, read ~/.bash_login. If the first two do not exist, read ~/.profile.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326288126&siteId=291194637