对比说明:
/etc/profile:为系统的每个用户设置环境信息和启动程序,当用户第一次登录时,该文件被执行,其配置对所有登录的用户都有效。当被修改时,必须重启才会生效。英文描述:”System wide environment and startup programs, for login setup.”

/etc/environment:系统的环境变量,/etc/profile是所有用户的环境变量,前者与登录用户无关,后者与登录用户有关,当同一变量在两个文件里有冲突时,以用户环境为准。

/etc/bashrc:为每个运行 bash shell 的用户执行该文件,当 bash shell 打开时,该文件被执行,其配置对所有使用bash的用户打开的每个bash都有效。当被修改后,不用重启只需要打开一个新的 bash 即可生效。英文描述:”System wide functions and aliases.”

~/.bash_profile:为当前用户设置专属的环境信息和启动程序,当用户登录时该文件执行一次。默认情况下,它用于设置环境变量,并执行当前用户的 .bashrc 文件。理念类似于 /etc/profile,只不过只对当前用户有效,也需要重启才能生效。(注意:Centos7系统命名为.bash_profile,其他系统可能是.bash_login或.profile。)

~/.bashrc:为当前用户设置专属的 bash 信息,当每次打开新的shell时,该文件被执行。理念类似于/etc/bashrc,只不过只对当前用户有效,不需要重启只需要打开新的shell即可生效。

~/.bash_logout:为当前用户,每次退出bash shell时执行该文件,可以把一些清理工作的命令放进这个文件。

/etc/profile.d/:此文件夹里是除/etc/profile之外其他的”application-specific startup files”。英文描述为”The /etc/profile file sets the environment variables at startup of the Bash shell. The /etc/profile.d directory contains other scripts that contain application-specific startup files, which are also executed at startup time by the shell.” 同时,这些文件”are loaded via /etc/profile which makes them a part of the bash “profile” in the same way anyway.” 因此可以简单的理解为是/etc/profile的一部分,只不过按类别或功能拆分成若干个文件进行配置了(方便维护和理解)。

注意事项
以上需要重启才能生效的文件,其实可以通过source xxx暂时生效。

文件的执行顺序为:当登录Linux时,首先启动/etc/environment和/etc/profile,然后启动当前用户目录下的~/.bash_profile,执行此文件时一般会调用~/.bashrc文件,而执行~/.bashrc时一般会调用/etc/bashrc,最后退出shell时,执行~/.bash_logout。简单来说顺序为:

登录时)/etc/environment –> /etc/profile(以及/etc/profile.d/里的文件) –> ~/.bash_profile –> (打开shell时)~/.bashrc –> /etc/bashrc –> (退出shell时)~/.bash_logout
————————————————
版权声明:本文为CSDN博主「siberiawolf61」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u010048823/article/details/51871825

/etc/profile和~/.bash_profile等文件的区别和联系的更多相关文章

  1. linux下/etc/profile、/etc/bashrc、~/.bashrc 和~/.bash_profile文件的区别

    这个一定要理解登录式shell和非登录式shell的区别,前者是完全切换用户,后者是不完全,就算切换过来了,你pwd时家目录还是之前的家目录,所以 登录式顺序为:/etc/bashrc---/etc/ ...

  2. 【总结】/etc/rc.d/rc.local 与 /etc/profile .bash_profile .bashrc 文件执行顺序

    登陆shell与交互式非登陆shell的区别 登录shell 所谓登录shell,指的是当用户登录系统时所取的那个 shell.登录shell属于交互式shell. 登录shell将查找4个不同的启动 ...

  3. /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 的区别(转)

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

  4. linux下系统启动时,几个配置文件 /etc/profile、~/.bash_profile 等几个文件的执行过程,先后顺序

    1. 在登录Linux时要执行文件的过程如下: 在刚登录Linux时, 首先启动 /etc/profile 文件, 然后再启动用户目录下的 ~/.bash_profile. ~/.bash_login ...

  5. 【转】Linux 之 /etc/profile、~/.bash_profile 等几个文件的执行过程

    原文网址:http://blog.csdn.net/ithomer/article/details/6322892 在登录Linux时要执行文件的过程如下:在刚登录Linux时,首先启动 /etc/p ...

  6. profile bashrc bash_profile之间的区别和联系

    profile bashrc bash_profile之间的区别和联系 博客分类: Linux   执行顺序为:/etc/profile -> (~/.bash_profile | ~/.bas ...

  7. Linux之profile、bash_profile、bashrc文件

    来自: profile.bash_profile.bashrc文件的作用与区别 1. profile 文件 1.1 profile 文件的作用 profile(/etc/profile),用于设置系统 ...

  8. profile(/etc/profile)和bash_profile的区别

    profile(/etc/profile)和bash_profile的区别 profile(/etc/profile),用于设置系统级的环境变量和启动程序,在这个文件下配置会对所有用户生效.当用户登录 ...

  9. linux关于profile 、bashrc 、.bash_profile、.bashrc的区别

    linux关于profile .bashrc ..bash_profile..bashrc的区别 - /etc/profile /etc/bashrc ~/.bash_profile ~/.bashr ...

随机推荐

  1. SpringBoot2.0 整合 SpringSecurity 框架,实现用户权限安全管理

    本文源码:GitHub·点这里 || GitEE·点这里 一.Security简介 1.基础概念 Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方 ...

  2. .NET轻松实现支付宝服务窗网页授权并获取用户相关信息

    前言: 最近在开发一个商业街区的聚合扫码支付功能,其中需要用到的有支付宝,微信两种支付方式,当然对于开发微信支付而已作为自己的老本行已经比较熟悉了,然而对于我来说支付宝支付还是头一次涉及到.这次项目中 ...

  3. goweb-搭建服务

    web应用简介 Web 应用在我们的生活中无处不在.看看我们日常使用的各个应用程序,它们要 么是 Web 应用,要么是移动 App 这类 Web 应用的变种.无论哪一种编程语言,只要 它能够开发出与人 ...

  4. 使用NDK(r20)编译FFmpeg

    前两天在论坛上看到一个问题,大意是怎么在UBUNTU下使用NDK-r20编译FFmpeg.我第一反应是不该用r20,因为我在很早前用过没有gcc版本的NDK,发现有很多问题不能编译,就立马回复了个使用 ...

  5. Django用websocket实现聊天室之筑基篇

    最近闲来无事,无意发现一个聊天室的前端UI,看着挺好看的但是没有聊天室的通信代码,于是想给它安装电池(通信部分),先看UI: 开始通信部分的工作: 使用的组件: Django1.11.13 chann ...

  6. SQL Serve里DBA要去改变的3个配置选项

    用安装向导安装了全新的SQL Server,最后你点击了完成按钮.哇噢~~~现在我们可以把我们的服务器进入生产了! 抱歉,那并不是真的,因为你的全新SQL Server默认配置是未优化的,一个合格的D ...

  7. django升级2.1python升级3.7时出现的错误:"trying to load '%s': %s" % (entry[1], e) django.template.library.InvalidTemplateLibrary:

    django升级2.1python升级3.7时出现如下的错误: "trying to load '%s': %s" % (entry[1], e) django.template. ...

  8. How to Check Device UUID or File System UUID. (Doc ID 1505398.1)

    How to Check Device UUID or File System UUID. (Doc ID 1505398.1) APPLIES TO: Linux OS - Version Orac ...

  9. Python—创建进程的三种方式

    方式一:os.fork() 子进程是从os.fork得到的值,然后赋值开始执行的.即子进程不执行os.fork,从得到的值开始执行. 父进程中fork之前的内容子进程同样会复制,但父子进程空间独立,f ...

  10. Python 获 Mozilla 和扎克伯格夫妇 40 余万美金资助

    Python 软件基金会近日发文宣布,收到来自 Mozilla Corporation 和 Chan Zuckerberg Initiative(CZI)的资金赞助,共计 407,000 美元.这笔款 ...