The difference between /etc/profile, /etc/bashrc, ~/.profile, ~/.bashrc under Linux

/etc/profile、/etc/bashrc、~/.profile、~/.bashrcThe difference under Linux system

/ect/ directory: affect the entire system

Insert picture description here

~/Directory: Affect the current user:

Insert picture description here

The difference between the four

  • /etc/profile:

Used to set system environment parameters: such as $PATH. The environment variable is effective for all users in the system.

  • ~/.bash_profile 或 ~/.profile:

Used to set user environment variables: similar to /etc/profile, but set for the user, this environment variable only takes effect for the current user.

  • /etc/bashrc 或者 /etc/bash.bashrc:

Initialize the system bash shell: Every user running the bash shell executes this file, such as initializing the bash settings, bash code completion, bash aliases, and bash colors. When the bash shell is opened, the file is read. When the user shell executes bash, run this file. bashrc is called bash.bashrc under Ubuntu

  • ~/.bashrc:

Initialize the current user bash shell: similar to /etc/bashrc, the scope is the current user, and it does not take effect for other users.

  • note:

The variables (global) set in /etc/profile can act on any user, while the variables (local) set in ~/.bashrc, etc. can only inherit the variables in /etc/profile, they are "parent-child" relationships .
~/.bash_profile is an interactive, login mode to enter bash operation, only when the user logs in will take effect.
~/.bashrc is run by entering bash interactively and non-login. The user is not necessarily logged in. As long as the command line is run as the user, the file will be read.

  • Execution order

When logging in to Linux, first start the /etc/profile file, and then start one of the ~/.bash_profile, ~/.bash_login or /.profile files in the user directory. The order of execution is: /.bash_profile, ~ /.bash_login, ~/.profile. If the ~/.bash_profile file exists, the ~/.bashrc file will generally be executed.

Guess you like

Origin blog.csdn.net/weixin_44307065/article/details/108895008