当前位置:网站首页>The role of /etc/profile, /etc/bashrc, ~/.bash_profile, ~/.bashrc files
The role of /etc/profile, /etc/bashrc, ~/.bash_profile, ~/.bashrc files
2022-07-31 14:26:00 【Stop losing your hair】
/etc/profile: This file sets the environment information for each user of the system. When the user logs in for the first time, this file is executed.And collect the shell settings from the configuration files in the /etc/profile.d directory.Think of system environment variables.
/etc/bashrc: Execute this file for every user running the bash shell, which is read when the bash shell is opened.
~/.bash_profile: Each user can use this file to enter shell information dedicated to their own use. When the user logs in, this file is executed only once! By default, he sets some environment variables and executes the user's.bashrc file.
~/.bashrc: This file contains bash information specific to your bash shell and is read when logging in and every time a new shell is opened.
~/.bash_logout: This file is executed every time you exit the system (exit the bash shell).
In addition, the variables (global) set in /etc/profile can act on any user, while the variables (local) set in ~/.bashrc can only inherit the variables in /etc/profile, theyIt's a "father-son" relationship.
~/.bash_profile is the interactive, login mode to enter the bash operation
~/.bashrc is the interactive non-login mode to enter the bash operation
Usually the two settings are roughly the same, so usually the former will callthe latter.
Several initialization files of bash - [Ubuntu]
(1) /etc/profile
Global (public) configuration, no matter which user is, the file will be read when logging in.
(2) /ect/bashrc
Ubuntu does not have this file, the corresponding one is /ect/bash.bashrc
It is also a global (public)
When bash is executed, no matter what it ismode, will read this file.
(3) ~/.profile
If bash is executed in login mode, read /.bash_profile, if it does not exist, read /.bash_login, if the first two do not exist, read ~/.profile.
Also, when logging in graphical mode, this file will be read even if /.bash_profile and /.bash_login exist.
(4) ~/.bash_login
If bash is executed in login mode, read /.bash_profile, if it does not exist, read /.bash_login, if the first two do not exist, read ~/.profile.
(5) ~/.bash_profile
Unbutu does not have this file by default, you can create a new one.
This file is read only when bash is executed as login.Usually this configuration file is also configured to read ~/.bashrc.
(6) ~/.bashrc
When bash is executed in non-login form, read this file.If executed in login form, this file will not be read.
(7) ~/.bash_logout
This file will only be read when it is logged out and in the form of longin.That is, when logging out in text mode, this file will be read, and when logging out in graphics mode, this file will not be read.
Here are a few examples on this machine:
When logging in in graphical mode, read sequentially: /etc/profile and ~/.profile
After logging in in graphical mode, when opening a terminal, read in sequence: /etc/bash.bashrc and ~/.bashrc
When logging in in text mode, read in sequence: /etc/bash.bashrc, /etc/profile and ~/.bash_profile
From other users su to this user, there are two cases:
(1) IfWith -l parameter (or - parameter, --login parameter), such as: su -l username, then bash is logged in, it will sequentially read the following configuration files: /etc/bash.bashrc, /etc/profile and ~/.bash_profile.
(2) If there is no -l parameter, then bash is non-login, it will read sequentially: /etc/bash.bashrc and ~/.bashrc
When logging out, or logging out of su user, if it is the longin method, then bash will read: ~/.bash_logout
When executing a custom shell file, if the "bash -l a.sh" method is used, bash will read the line: /etc/profile and ~/.bash_profile, if you use other methods, such as: bash a.sh, ./a.sh, sh a.sh (this does not belong to the bash shell), it will not read any of the above files.
The above example always reads /.bash_profile, if the file does not exist, then reads /.bash_login, if the first two do not exist, reads ~/.profile.
边栏推荐
- AI cocoa AI frontier introduction (7.31)
- el-tooltip的使用
- Sentinel流量控制
- 使用NVM进行node版本切换管理
- Shell脚本经典案例:探测批量主机是否存活
- An article makes it clear!What is the difference and connection between database and data warehouse?
- DELL SC compellent 康贝存储系统怎么抓取配置信息
- jOOQ 3.14 released - SQL/XML and SQL/JSON support
- 组合系列--有排列就有组合
- UnityShader入门学习(三)——Unity的Shader
猜你喜欢
尚硅谷-JVM-内存和垃圾回收篇(P1~P203)
In the future, the interviewer asks you why it is not recommended to use Select *, please answer him out loud!
Linux bash: redis-server: command not found
OpenShift 4 - 定制 RHACS 安全策略,阻断生产集群使用高风险 Registry
Analysis of the startup source code of hyperf (2) - how the request reaches the controller
Combination series - there are combinations when there are arrangements
The recently popular domestic interface artifact Apipost experience
最近很火的国产接口神器Apipost体验
MySQL玩到这种程度,难怪大厂抢着要!
AWS implements scheduled tasks - Lambda+EventBridge
随机推荐
Shell project combat 1. System performance analysis
UnityShader入门学习(二)——渲染流水线
Redis 】 【 publish and subscribe message
AI cocoa AI frontier introduction (7.31)
Numbers that appear only once in LeetCode
Buffer 与 拥塞控制
技能大赛训练题:交换机虚拟化练习
UnityShader入门学习(一)——GPU与Shader
消息队列消息数据存储MySQL表设计
搭建私有的的Nuget包服务器教程
IDEA连接MySQL数据库并使用数据
纸质说明书秒变3D动画,斯坦福大学吴佳俊最新研究,入选ECCV 2022
线程池的使用二
Uniapp WeChat small application reference standard components
Recommendation System - Recall Phase - 2013: DSSM (Twin Towers Model) [Embedding (Semantic Vector) Recall] [Microsoft]
MySQL [subquery]
jOOQ 3.14 released - SQL/XML and SQL/JSON support
C# Get network card information NetworkInterface IPInterfaceProperties
技能大赛训练题:域用户和组织单元的创建
/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件的作用