在 Linux 系统中,.bashrc
, .bash_profile
, .profile
和 /etc/profile
这几个文件都有各自的用途,它们在不同的场景下被加载和执行。下面是对这几个文件的区别和作用的详细介绍:
1. ~/.bashrc
- 描述:这个文件是针对每个用户的 bash shell 的个人配置文件。
- 加载时机:每当用户打开一个新的交互式终端窗口(或标签页)时,
~/.bashrc
就会被读取并执行一次。 - 用途:通常用于设置个人的环境变量、别名定义、shell 函数以及其他个性化配置。
- 示例内容:
# Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # User specific aliases and functions alias ll='ls -l'
2. ~/.bash_profile
- 描述:也是针对每个用户的 bash shell 的个人配置文件,但是它的加载优先级高于
~/.bashrc
。 - 加载时机:在用户登录系统时被读取和执行一次。
- 用途:通常用于设置全局环境变量,例如
JAVA_HOME
、PATH
等。 - 示例内容:
# Get the aliases and functions if [ -f