当前位置:网站首页>/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。
边栏推荐
- OAuth2:四种授权方式
- Motion capture system for end-positioning control of flexible manipulators
- Shell script classic case: backup of files
- 百度网盘安装在c盘显示系统权限限制的解决方法
- Linux bash: redis-server: command not found
- leetcode: 485. Maximum number of consecutive 1s
- Why do we need to sub-library and sub-table?
- The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
- SetoolKit User Guide
- 技能大赛dhcp服务训练题
猜你喜欢

OAuth2:使用JWT令牌

Nuget package and upload tutorial

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

最近很火的国产接口神器Apipost体验

Miller_Rabin 米勒拉宾概率筛【模板】

“听我说谢谢你”还能用古诗来说?清华搞了个“据意查句”神器,一键搜索你想要的名言警句...

CodeIgniter 打开错误日志

技能大赛训练题:域用户和组织单元的创建

OAuth2:资源服务器

DELL SC compellent 康贝存储系统怎么抓取配置信息
随机推荐
AWS实现定时任务-Lambda+EventBridge
技能大赛训练题: 子网掩码划分案例
技能大赛训练题:登录安全加固
Sentinel限流和异常处理
自制的数据库安全攻防题,相关靶机自己制作
leetcode:2032. 至少在两个数组中出现的值
The pre-sale of the new Hyundai Paristi is open, and safety and comfort are not lost
LeetCode rotate array
DELL SC compellent 康贝存储系统怎么抓取配置信息
49.【拷贝构造函数与重载】
STM32的CAN过滤器
endnote引用
龟速乘【模板】
八大排序汇总及其稳定性
Resnet&API
The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
Small test knife: Go reflection helped me convert Excel to Struct
线程池的使用二
Shell script classic case: detecting whether a batch of hosts is alive
最近很火的国产接口神器Apipost体验