当前位置:网站首页>/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 23道经典面试吊打面试官
- AWS实现定时任务-Lambda+EventBridge
- Samba 远程命令执行漏洞(CVE-2017-7494)
- Motion capture system for end-positioning control of flexible manipulators
- 技能大赛训练题:MS15_034漏洞验证与安全加固
- Unity study notes Description of AVPro video jump function (Seeking)
- SetoolKit使用指南
- 技能大赛dhcp服务训练题
- OAuth2:微服务权限校验Session共享
- 【redis】发布和订阅消息
猜你喜欢

sentinel与nacos持久化

技能大赛训练题:MS15_034漏洞验证与安全加固

五个维度着手MySQL的优化
![MySQL [aggregate function]](/img/2e/8f92cedeb8c2a99ec682869c77bc67.png)
MySQL [aggregate function]

Motion capture system for end-positioning control of flexible manipulators

Resnet&API

已解决(pymysqL连接数据库报错)pymysqL.err.ProgrammingError: (1146,“Table ‘test.students‘ doesn‘t exist“)

An article makes it clear!What is the difference and connection between database and data warehouse?

A detailed explanation of the usage of Async and Await in C#

How to grab configuration information for DELL SC compellent storage system
随机推荐
ML、DL、CV常见的问题整理
DELL SC compellent 康贝存储系统怎么抓取配置信息
以后面试官问你 为啥不建议使用Select *,请你大声回答他!
SetoolKit User Guide
All-round visual monitoring of the Istio microservice governance grid (microservice architecture display, resource monitoring, traffic monitoring, link monitoring)
[QNX Hypervisor 2.2用户手册]9.14 safety
纸质说明书秒变3D动画,斯坦福大学吴佳俊最新研究,入选ECCV 2022
五个维度着手MySQL的优化
redhat/openssl generates a self-signed ca certificate and uses it
MySQL 23 classic interviews hang the interviewer
Sentinel服务熔断和降级
The 232-layer 3D flash memory chip is here: the single-chip capacity is 2TB, and the transmission speed is increased by 50%
AWS实现定时任务-Lambda+EventBridge
Open Inventor 10.12 Major Improvements - Harmony Edition
技能大赛训练题:MS15_034漏洞验证与安全加固
el-tooltip的使用
20.nn.Module
Analysis of the startup source code of hyperf (2) - how the request reaches the controller
The magic of SQL MERGE statement (detailed instructions)
海康摄像机取流RTSP地址规则说明