当前位置:网站首页>/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。
边栏推荐
- Why do we need to sub-library and sub-table?
- For enterprises in the digital age, data governance is difficult, but it should be done
- 技能大赛训练题:交换机的远程管理
- MySQL [subquery]
- OAuth2:微服务权限校验Session共享
- 常用工具命令速查表
- Redis与分布式:哨兵模式
- Comparison of Optical Motion Capture and UWB Positioning Technology in Multi-agent Cooperative Control Research
- OAuth2:搭建授权服务器
- 五个维度着手MySQL的优化
猜你喜欢
Uniapp WeChat small application reference standard components
Selenium自动化测试之Selenium IDE
A detailed explanation of the usage of Async and Await in C#
For enterprises in the digital age, data governance is difficult, but it should be done
Small test knife: Go reflection helped me convert Excel to Struct
拥塞控制,CDN,端到端
【redis】发布和订阅消息
C# Get network card information NetworkInterface IPInterfaceProperties
八大排序汇总及其稳定性
使用NVM进行node版本切换管理
随机推荐
已解决(pymysqL连接数据库报错)pymysqL.err.ProgrammingError: (1146,“Table ‘test.students‘ doesn‘t exist“)
csdn发文助手问题
SetoolKit User Guide
[Pytorch] F.softmax() method description
五个维度着手MySQL的优化
技能大赛训练题:域用户和组织单元的创建
OAuth2:四种授权方式
自制的数据库安全攻防题,相关靶机自己制作
The recently popular domestic interface artifact Apipost experience
Redis 】 【 publish and subscribe message
MySQL [aggregate function]
Selenium自动化测试之Selenium IDE
IDEA连接MySQL数据库并使用数据
redhat/openssl生成自签ca证书并使用
ML, DL, CV common problems sorting
Shell script classic case: detecting whether a batch of hosts is alive
[Pytorch] torch.argmax() usage
MySQL 23道经典面试吊打面试官
redhat/openssl generates a self-signed ca certificate and uses it
OAuth2:微服务权限校验Session共享