profile bashrc bash_profile 之间的区别和联系

/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置.

/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.

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

~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该文件被读取.(每个用户都有一个.bashrc文件,在用户目录下)

~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件.

另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是"父子"关系.
 
~/.bash_profile 是交互式、login 方式进入 bash 运行的
~/.bashrc 是交互式 non-login 方式进入 bash 运行的
通常二者设置大致相同,所以通常前者会调用后者。

在登录Linux时要执行文件的过程如下:

在刚登录Linux时,首先启动 /etc/profile 文件,然后再启动用户目录下的 ~/.bash_profile、 ~/.bash_login或 ~/.profile文件中的其中一个,

执行的顺序为:~/.bash_profile、 ~/.bash_login、 ~/.profile。

如果 ~/.bash_profile文件存在的话,一般还会执行 ~/.bashrc文件。

因为在 ~/.bash_profile文件中一般会有下面的代码:
if [ -f ~/.bashrc ] ; then

. ./bashrc

fi

~/.bashrc中,一般还会有以下代码:
if [ -f /etc/bashrc ] ; then

. /bashrc

fi

所以,~/.bashrc会调用 /etc/bashrc文件。最后,在退出shell时,还会执行 ~/.bash_logout文件。

执行顺序为:/etc/profile -> (~/.bash_profile | ~/.bash_login | ~/.profile) -> ~/.bashrc -> /etc/bashrc -> ~/.bash_logout

关于各个文件的作用域,在网上找到了以下说明:

(1)/etc/profile: 此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置。

(2)/etc/bashrc: 为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取。

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

(4)~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取。

(5)~/.bash_logout: 当每次退出系统(退出bash shell)时,执行该文件. 另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承 /etc/profile中的变量,他们是"父子"关系。

(6)~/.bash_profile 是交互式、login 方式进入 bash 运行的~/.bashrc 是交互式 non-login 方式进入 bash 运行的通常二者设置大致相同,所以通常前者会调用后者。

时间: 2024-08-04 08:03:31

profile bashrc bash_profile 之间的区别和联系的相关文章

profile bashrc bash_profile之间的区别和联系

转载:http://talentluke.iteye.com/blog/1541702 执行顺序为:/etc/profile -> (~/.bash_profile | ~/.bash_login | ~/.profile) -> ~/.bashrc -> /etc/bashrc -> ~/.bash_logout 关于各个文件的作用域,在网上找到了以下说明: (1)/etc/profile: 此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行,并从/etc/pr

linux /etc/profile bashrc bash_profile

文件: /etc/profile  ~/.bashrc  和  ~/.bash_profile 的使用区别: /etc/profile: 全局 环境变量等,在机器重启后执行一次, 用于设置环境变量,更改一些内核参数等命令. /etc/bashrc : 全局登陆  变量,如 alias. bashrc  和 bash_profile : 登陆执行的动作,主要用于设置 别名等 小动作. bash_profile 是每次登陆都会执行,执行过程中调用 bashrc ,bashrc 不是每次登陆都会执行.

Linux中profile、bashrc、bash_profile之间的区别和联系

/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集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 f

Linux_linux中profile、bashrc、bash_profile之间的区别和联系(转)

/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集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

【转载】Linux中profile、bashrc、bash_profile之间的区别和联系

如果你想对所有的使用bash的用户修改某个配置并在以后打开的bash都生效的话可以修改这个文件,修改这个文件不用重启,重新打开一个bash即可生效.~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件. 此文件类似于/etc/profile,也是需要需要重启才会生效,/etc/profile对所有用户生效,~/.bash_profile只对当前用户生效. ~/.ba

Linux中profile、bashrc、bash_profile之间的区别和联系(转)

/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集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 f

(转) Linux中profile、bashrc、bash_profile之间的区别和联系

原文地址:http://blog.csdn.net/chenchong08/article/details/7833242 /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. 英文描述为: # /etc/profile # System wide environment and startup programs, for login setup# Functions and ali

老男孩教育每日一题-第76天-说说/etc/profile /etc/bashrc .bashrc .bash_profile的区别

参考答案: 每个文件的含义 /etc/profile    主要用是系统的环境变量,同时我们也放些别名/etc/bashrc    主要用来存放系统的别名和自己定义的函数(都可以放到 /etc/profile中).bashrc       是用户自己定义的别名.bash_profile  是用户自己定义的环境变量 文件之间的联系: 测试方法在/etc/bashrc /etc/profile .bashrc .bash_profile 这四个文件的第一行和最后一行添加上标记 /etc/profil

bashrc,bash_profile和/etc/profile

bashrc,bash_profile和/etc/profile 最近老出现在shell里面能跑的程序用鼠标双击app去不能跑.究其原因是因为环境变量的问题. 在类unix系统中一般有三个bash配置文件: ~/.bashrc 当前用户使用的配置文件 ~/.bash_profile 当前用户使用的配置文件 /etc/profile 所有用户都会继承的环境配置文件 我们需要搞清楚/etc/profile, ~/.bash_profile和~/.bashrc这几个文件的加载顺序. 一般来说~/.ba