【Linux】Linux下 环境变量/etc/profile、/etc/bashrc、~/.bashrc的区别【转】

简介: 转自:http://blog.csdn.net/qiao1245/article/details/44650929--------------------------------------------------------------------------------------------...

转自:http://blog.csdn.net/qiao1245/article/details/44650929

------------------------------------------------------------------------------------------------------------------------------------------------

==========================================================================================

最近配置了JAVA和Scala的环境变量,发现自己对Linux下 /etc/profile、/etc/bashrc、~/.bashrc的区别不是特别清楚,特此查阅了相关资料,整理下来,供以后查阅。如有错误之处,还望各位朋友批评指正。 
①/etc/profile: 
该文件登录操作系统时,为每个用户设置环境信息,当用户第一次登录时,该文件被执行。也就是说这个文件对每个shell都有效,用于获取系统的环境信息。

# /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.

②/etc/bashrc: 
为每一个运行bash shell的用户执行此文件,当bash shell被打开时,该文件被读取。也就是说,当用户shell执行了bash时,运行这个文件。

# /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.
 

③~/.bashrc 
该文件存储的是专属于个人bash shell的信息,当登录时以及每次打开一个新的shell时,执行这个文件。在这个文件里可以自定义用户专属的个人信息。

那么在用户登录系统时候,相关的文件执行顺序是什么呢。 
在刚登录Linux时,首先启动 /etc/profile 文件,然后再启动用户目录下的 ~/.bash_profile、 ~/.bash_login或 ~/.profile文件中的其中一个,执行的顺序为:~/.bash_profile、 ~/.bash_login、 ~/.profile。如果 ~/.bash_profile文件存在的话,一般还会执行 ~/.bashrc文件。

相关文章
|
26天前
|
存储 安全 Shell
【Shell 命令集合 系统设置 】Linux 置环境变量 grpunconv命令 使用指南
【Shell 命令集合 系统设置 】Linux 置环境变量 grpunconv命令 使用指南
29 0
|
26天前
|
存储 Shell Linux
【Shell 命令集合 系统设置 】Linux 置环境变量 grpconv命令 使用指南
【Shell 命令集合 系统设置 】Linux 置环境变量 grpconv命令 使用指南
26 0
|
27天前
|
存储 Unix Linux
Linux 下文件和目录的本质区别和组成
Linux 下文件和目录的本质区别和组成
31 0
|
27天前
|
Linux API 调度
Linux系统驱动跟裸机驱动的区别
Linux系统驱动跟裸机驱动的区别
27 0
|
28天前
|
存储 安全 Linux
Linux环境变量:不可或缺的系统组成部分
Linux环境变量:不可或缺的系统组成部分
39 0
|
26天前
|
存储 Shell Linux
【Shell 命令集合 系统设置 】⭐ Linux 取消或删除已设置的环境变量 unset命令 使用指南
【Shell 命令集合 系统设置 】⭐ Linux 取消或删除已设置的环境变量 unset命令 使用指南
34 0
|
8天前
|
Linux 网络安全
linux免密登录报错 Bad owner or permissions on /etc/ssh/ssh_config.d/05-redhat.conf
linux免密登录报错 Bad owner or permissions on /etc/ssh/ssh_config.d/05-redhat.conf
17 1
|
28天前
|
存储 Linux 编译器
Linux 交叉编译第三方库需要设置的环境变量
Linux 交叉编译第三方库需要设置的环境变量
22 0
|
23天前
|
存储 算法 Shell
【Linux 环境变量相关】深入理解Linux下 CMake、Shell 与环境变量的交互(二)
【Linux 环境变量相关】深入理解Linux下 CMake、Shell 与环境变量的交互
44 0
|
26天前
|
存储 Java Shell
【Shell 命令集合 系统设置 】⭐⭐⭐Linux 设置环境变量setenv命令 使用指南
【Shell 命令集合 系统设置 】⭐⭐⭐Linux 设置环境变量setenv命令 使用指南
27 0