长求总:全局变量在/etc目录下,用户自定义在~/目录下,仅针对bash shell就找%bashrc%类文件
1. /etc/profile
对所有用户、所有shell均有效
登陆操作系统后,该文件被读取,从/etc/profile.d的配置文件中搜集shell相关设置
生效方式:source命令或重启操作系统
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
2. /etc/.bashrc 或 /etc/bash.bashrc
对所有运行bash shell的用户生效
打开bash shell时,该文件被读取
生效方式:重启bash shell
# System-wide .bashrc file for interactive bash(1) shells. # To enable the settings / commands in this file for login shells as well, # this file has to be sourced in /etc/profile.
3.~/.bash_profile >> ~/.bash_login >> ~/.profile
对当前用户生效
用户登陆操作系统后,根据优先级次序读取该用户的文件
生效方式:source命令或重启操作系统
# ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login exists.
4.~/.bashrc
对当前运行bash shell的用户生效
打开bash shell时,该用户的文件被读取(一般在~/.bash_profile之后)
生效方式:重启bash shell
# ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) for examples
5.~/.bash_logout
对当前关闭bash shell的用户生效
关闭bash shell时,该用户的文件被读取
生效方式:重启bash shell
# ~/.bash_logout: executed by bash(1) when login shell exits.