linux下文件/etc/profile、/etc/bashrc、~/.bashrc 和~/.bash_profile文件的区别 && 用户登录后的加载配置文件的顺序

//整理一些关于环境变量的笔记,方便以后回顾

1、环境变量配置原因

环境变量:指定一个目录,运行软件或程序的时候,相关程序会按照目录寻找相关文件

原因:使你可以在非安装目录运行软件

2、环境变量的设置方法

(1) 控制台,仅临时有效,仅针对于当前shell

  • $PATH="$PATH:/opt/tomcat"

 

 

需要给某个用户权限只需要在其个人主目录想修改即可。修改方法类似于/etc/profile文件

3、~/.bashrc、~/.bash_profile、~/.bash.profile和/etc/bashrc和/etc/profile的区别

 

 

 

 

 

1 # /etc/profile
2 
3 # System wide environment and startup programs, for login setup
4 # Functions and aliases go in /etc/bashrc
5 
6 # It's NOT a good idea to change this file unless you know what you
7 # are doing. It's much better to create a custom.sh shell script in
8 # /etc/profile.d/ to make custom changes to your environment, as this
9 # will prevent the need for merging in future updates.

 

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

1 # /etc/bashrc
2 
3 # System wide functions and aliases
4 # Environment stuff goes in /etc/profile
5 
6 # It's NOT a good idea to change this file unless you know what you
7 # are doing. It's much better to create a custom.sh shell script in
8 # /etc/profile.d/ to make custom changes to your environment, as this
9 # will prevent the need for merging in future updates.

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

④~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该 文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件.

1、在登录时,操作系统定制用户环境时使用的第一个文件就是  /etc/profile  ,此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行。
2、在登录时操作系统使用的第二个文件是  /etc/environment  ,系统在读取你自己的profile  前,设置环境文件的环境变量。
3、在登录时用到的第三个文件是.profile文件,每个用户都可使用该文件输入专用于自己使用的shell信息,,该 文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件。/etc/bashrc:为每一个运行bash shell的用户执行此文件。当bash shell 被打开时,该文件被读取。

posted @ 2017-03-23 01:10  苦瓜的甜  阅读(4566)  评论(0编辑  收藏  举报