如何寻找设置了PATH的配置文件?

当我们执行 echo $PATH的时候,想知道哪里设置了PATH变量。以下罗列了可能设置PATH的配置文件。

1. ~/.bashrc

这个配置文件在用户的家目录下,内容加载了/etc/bashrc配置文件的内容。例如:

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

2. ~/.bash_profile

这个配置文件也是在用户的家目录下,但一般修改~/.bashrc即可。


3. /etc/profile,/etc/bashrc

这两个文件最好不要改动,如果要添加内容,让所有的用户都使用到,则可以在/etc/profile.d/下建立一个custom.sh脚本文件。

注意:两者的区别在于:

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
我们看到,设置函数和alias是到/etc/bashrc里,系统环境和登陆后启动的程序,到/etc/profile。 这两个文件最好都不要改变,两个配置文件都提示,要到/etc/profile.d/下建立一个custom.sh文件。



综合以上表述,我们可以修改/添加登陆配置的地方有三个:

~/.bashrc 

~/.bash_profile 

/etc/profile.d/


你可能感兴趣的:(linux)