当前位置:网站首页>/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件的作用
/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件的作用
2022-07-31 14:10:00 【别掉头发啦】
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行。并从/etc/profile.d目录的配置文件中搜集shell的设置。可以认为系统环境变量。
/etc/bashrc:为每一个运行bash shell的用户执行此文件,当bash shell被打开时,该文件被读取。
~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件。
~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该文件被读取。
~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件。
另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是"父子"关系。
~/.bash_profile 是交互式、login 方式进入 bash 运行的
~/.bashrc 是交互式 non-login 方式进入 bash 运行的
通常二者设置大致相同,所以通常前者会调用后者。
bash的几个初始化文件 - [Ubuntu]
(1)/etc/profile
全局(公有)配置,不管是哪个用户,登录时都会读取该文件。
(2)/ect/bashrc
Ubuntu没有此文件,与之对应的是/ect/bash.bashrc
它也是全局(公有)的
bash执行时,不管是何种方式,都会读取此文件。
(3)~/.profile
若bash是以login方式执行时,读取/.bash_profile,若它不存在,则读取/.bash_login,若前两者不存在,读取~/.profile。
另外,图形模式登录时,此文件将被读取,即使存在/.bash_profile和/.bash_login。
(4)~/.bash_login
若bash是以login方式执行时,读取/.bash_profile,若它不存在,则读取/.bash_login,若前两者不存在,读取~/.profile。
(5)~/.bash_profile
Unbutu默认没有此文件,可新建。
只有bash是以login形式执行时,才会读取此文件。通常该配置文件还会配置成去读取~/.bashrc。
(6)~/.bashrc
当bash是以non-login形式执行时,读取此文件。若是以login形式执行,则不会读取此文件。
(7)~/.bash_logout
注销时,且是longin形式,此文件才会读取。也就是说,在文本模式注销时,此文件会被读取,图形模式注销时,此文件不会被读取。
下面是在本机的几个例子:
图形模式登录时,顺序读取:/etc/profile和~/.profile
图形模式登录后,打开终端时,顺序读取:/etc/bash.bashrc和~/.bashrc
文本模式登录时,顺序读取:/etc/bash.bashrc,/etc/profile和~/.bash_profile
从其它用户su到该用户,则分两种情况:
(1)如果带-l参数(或-参数,–login参数),如:su -l username,则bash是login的,它将顺序读取以下配置文件:/etc/bash.bashrc,/etc/profile和~/.bash_profile。
(2)如果没有带-l参数,则bash是non-login的,它将顺序读取:/etc/bash.bashrc和~/.bashrc
注销时,或退出su登录的用户,如果是longin方式,那么bash会读取:~/.bash_logout
执行自定义的shell文件时,若使用“bash -l a.sh”的方式,则bash会读取行:/etc/profile和~/.bash_profile,若使用其它方式,如:bash a.sh, ./a.sh,sh a.sh(这个不属于bash shell),则不会读取上面的任何文件。
上面的例子凡是读取到/.bash_profile的,若该文件不存在,则读取/.bash_login,若前两者不存在,读取~/.profile。
边栏推荐
- 五个维度着手MySQL的优化
- Numbers that appear only once in LeetCode
- Redis与分布式:主从复制
- ECCV 2022 | Robotic Interaction Perception and Object Manipulation
- MySQL [subquery]
- redhat/openssl生成自签ca证书并使用
- All-round visual monitoring of the Istio microservice governance grid (microservice architecture display, resource monitoring, traffic monitoring, link monitoring)
- Sentinel流量控制
- 尚硅谷-JVM-内存和垃圾回收篇(P1~P203)
- Introduction to BigDecimal, common methods
猜你喜欢

Nuget package and upload tutorial

五个维度着手MySQL的优化

纸质说明书秒变3D动画,斯坦福大学吴佳俊最新研究,入选ECCV 2022

ECCV 2022 | Robotic Interaction Perception and Object Manipulation

「面经分享」西北大学 | 字节 生活服务 | 一面二面三面 HR 面

How to grab configuration information for DELL SC compellent storage system

Resolved (pymysqL connect to the database error) pymysqL. Err. ProgrammingError: (1146, "Table" test. Students' doesn 't exist ")

Redis与分布式:哨兵模式

新款现代帕里斯帝预售开启,安全、舒适一个不落

C# using ComboBox control
随机推荐
csdn发文助手问题
MySQL【聚合函数】
MySQL [subquery]
SetoolKit User Guide
OAuth2:微服务权限校验Session共享
A detailed explanation of the usage of Async and Await in C#
Resnet&API
动作捕捉系统用于柔性机械臂的末端定位控制
How to grab configuration information for DELL SC compellent storage system
技能大赛训练题:交换机的远程管理
ADS communicate with c #
C# using ComboBox control
“听我说谢谢你”还能用古诗来说?清华搞了个“据意查句”神器,一键搜索你想要的名言警句...
MySQL【子查询】
Tortoise speed by "template"
Resolved (pymysqL connect to the database error) pymysqL. Err. ProgrammingError: (1146, "Table" test. Students' doesn 't exist ")
Use of el-tooltip
AI cocoa AI frontier introduction (7.31)
[QNX Hypervisor 2.2用户手册]9.14 safety
SetoolKit使用指南