对比说明:
/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. python强大的绘图模块matplotlib示例讲解

    Matplotlib 是 Python 的绘图库.作为程序员,经常需要进行绘图,在我自己的工作中,如果需要绘图,一般都是将数据导入到excel中,然后通过excel生成图表,这样操作起来还是比较繁琐的 ...

  2. java获取月的第一天和最后一天

    在Java中获取月的第一天和最后一天主要是通过Calendar对象来实现. /** * 获取月的第一天 * * @param month 月 */ private String getMonthBeg ...

  3. 一起学Android之AsyncTask

    概述 在Android开发中,为了方便我们在后台线程中执行操作,然后将结果发送给主线程,从而在主线程中进行UI更新等操作,Anddroid开发框架提供了一个助手类AsyncTask,它对Thread和 ...

  4. .net core 2.1 Swagger 配置

    1.先创建 .net core Web 应用程序,选择API 2.安装 Nuget 包:Swashbuckle.AspNetCore Install-Package Swashbuckle.AspNe ...

  5. fiddler抓包syntaxview窗口乱码

    只需再fiddler界面GO往右第二个Decode点击一下,让他出现蓝色边框即可 注意:抓取前的他不会进行自动解码,要再重新刷新页面才能获取界面后的内容

  6. cookie --中间件

    Cookie简介 cookie是服务器存储在用户计算机中的变量,可以让我们用同一个浏览器访问同一个域名的时共享数据. HTTP是一种无状态协议,简单来说,当你从一个页面,然后跳转到同站点的另一个页面时 ...

  7. cesium 入门开发系列地图鹰眼功能(附源码下载)

    前言 cesium 入门开发系列环境知识点了解:cesium api文档介绍,详细介绍 cesium 每个类的函数以及属性等等cesium 在线例子 内容概览 cesium 结合 leaflet 实现 ...

  8. Hacking/Penetrating tester bookmark collection

    Blogs http://carnal0wnage.blogspot.com/ http://www.mcgrewsecurity.com/ http://www.gnucitizen.org/blo ...

  9. cookies和sessions组件

    目录 cookie与session cookie介绍 session介绍 token django操作cookie 设置cookie 获取cookie 删除cookie 基于cookie实现的登录认证 ...

  10. JAVA 高级特性枚举和泛型

    枚举: 语法:  public enum 枚举名 { 枚举值表(罗列所有值) }  例如:  public enum EnumTest{MON,TUE,WED.THU,FRI,SAT,SUN} 枚举操 ...